Beispiel #1
0
 public int GetSubModelCount <TModel>(string modelId)
 {
     using (var Redis = RedisClientManager.GetReadOnlyClient())
     {
         return(Redis.GetHashCount(RedisKeyFactory.SubModelKey <TModel>(modelId)));
     }
 }
Beispiel #2
0
        public virtual void Delete <T>(T model, bool IsRemoveSubModel = true) where T : IRedisModelBase
        {
            using (var Redis = RedisClientManager.GetClient())
            {
                if (model != null)
                {
                    string modelKey = GetKey <T>(model);

                    Redis.Remove(modelKey);

                    Redis.RemoveItemFromSortedSet(RedisKeyFactory.ListAllKeys <T>(), modelKey);

                    Redis.IncrementValueBy(RedisKeyFactory.ListAllNumKeys <T>(), -1);

                    if (GetAllCount <T>() == 0)
                    {
                        Redis.Remove(RedisKeyFactory.ListAllNumKeys <T>());
                    }

                    BuildIndex <T>(model, true);

                    if (IsRemoveSubModel)
                    {
                        Redis.Remove(RedisKeyFactory.SubModelKey <T>(model.Id));
                    }
                }
            }
        }
Beispiel #3
0
 public List <string> GetAllSubModelIds <TModel>(string modelId)
     where TModel : IRedisModelBase
 {
     using (var Redis = RedisClientManager.GetReadOnlyClient())
     {
         return(Redis.GetHashKeys(RedisKeyFactory.SubModelKey <TModel>(modelId)));
     }
 }
Beispiel #4
0
 public bool ExistSubModel <TModel, TSubModel>(string modelId, string subModelId)
     where TModel : IRedisModelBase
     where TSubModel : IRedisModelBase
 {
     using (var Redis = RedisClientManager.GetReadOnlyClient())
     {
         return(Redis.HashContainsEntry(RedisKeyFactory.SubModelKey <TModel>(modelId), GetKey <TSubModel>(subModelId)));
     }
 }
Beispiel #5
0
 public virtual bool DeleteSubModel <TModel, TSubModel>(string modelId, string subModelId)
     where TModel : IRedisModelBase
     where TSubModel : IRedisModelBase
 {
     using (var Redis = RedisClientManager.GetClient())
     {
         return(Redis.RemoveEntryFromHash(RedisKeyFactory.SubModelKey <TModel>(modelId), GetKey <TSubModel>(subModelId)));
     }
 }
Beispiel #6
0
 public virtual bool SetSubModel <TModel, TSubModel>(string modelId, TSubModel subModel)
     where TModel : IRedisModelBase
     where TSubModel : IRedisModelBase
 {
     using (var Redis = RedisClientManager.GetClient())
     {
         return(Redis.SetEntryInHash(RedisKeyFactory.SubModelKey <TModel>(modelId), GetKey <TSubModel>(subModel), JsonConvert.SerializeObject(subModel)));
     }
 }
Beispiel #7
0
 public TSubModel GetSubModel <TModel, TSubModel>(string modelId, string subModelId, bool isFullSubModelKey = false)
     where TModel : IRedisModelBase
     where TSubModel : IRedisModelBase
 {
     using (var Redis = RedisClientManager.GetReadOnlyClient())
     {
         var subModelJSONString = Redis.GetValueFromHash(RedisKeyFactory.SubModelKey <TModel>(modelId), isFullSubModelKey ? subModelId : GetKey <TSubModel>(subModelId));
         if (string.IsNullOrWhiteSpace(subModelJSONString))
         {
             return(default(TSubModel));
         }
         else
         {
             return(JsonConvert.DeserializeObject <TSubModel>(subModelJSONString));
         }
     }
 }
Beispiel #8
0
        public List <TSubModel> GetAllSubModelsByType <TModel, TSubModel>(string modelId)
            where TModel : IRedisModelBase
            where TSubModel : IRedisModelBase
        {
            List <TSubModel> subModels = new List <TSubModel>();
            var subModelIds            = GetAllSubModelIdsByType <TModel, TSubModel>(modelId).ToArray();

            using (var Redis = RedisClientManager.GetReadOnlyClient())
            {
                List <string> values = Redis.GetValuesFromHash(RedisKeyFactory.SubModelKey <TModel>(modelId), subModelIds);
                foreach (var v in values)
                {
                    if (!string.IsNullOrWhiteSpace(v))
                    {
                        subModels.Add(JsonConvert.DeserializeObject <TSubModel>(v));
                    }
                }

                return(subModels);
            }
        }