public int GetSubModelCount <TModel>(string modelId) { using (var Redis = RedisClientManager.GetReadOnlyClient()) { return(Redis.GetHashCount(RedisKeyFactory.SubModelKey <TModel>(modelId))); } }
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)); } } } }
public List <string> GetAllSubModelIds <TModel>(string modelId) where TModel : IRedisModelBase { using (var Redis = RedisClientManager.GetReadOnlyClient()) { return(Redis.GetHashKeys(RedisKeyFactory.SubModelKey <TModel>(modelId))); } }
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))); } }
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))); } }
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))); } }
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)); } } }
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); } }