public IBaseContainerBag Get(string key, bool isFullKey = false) { var value = base.Get(key, isFullKey); if (value == null) { return(null); } return(StackExchangeRedisExtensions.Deserialize <IBaseContainerBag>((RedisValue)value)); }
public IContainerItemCollection Get(string key) { if (string.IsNullOrEmpty(key)) { return(null); } if (!CheckExisted(key)) { return(null); //InsertToCache(key, new ContainerItemCollection()); } var cacheKey = GetFinalKey(key); var value = _cache.StringGet(cacheKey); return(StackExchangeRedisExtensions.Deserialize <IContainerItemCollection>(value)); }
public IDictionary <string, TBag> GetAll <TBag>() where TBag : IBaseContainerBag { #region 旧方法(没有使用Hash之前) //var itemCacheKey = ContainerHelper.GetItemCacheKey(typeof(TBag), "*"); ////var keyPattern = string.Format("*{0}", itemCacheKey); //var keyPattern = GetFinalKey(itemCacheKey); //var keys = GetServer().Keys(pattern: keyPattern); //var dic = new Dictionary<string, TBag>(); //foreach (var redisKey in keys) //{ // try // { // var bag = Get(redisKey, true); // dic[redisKey] = (TBag)bag; // } // catch (Exception) // { // } //} #endregion var key = ContainerHelper.GetItemCacheKey(typeof(TBag), ""); key = key.Substring(0, key.Length - 1); //去掉:号 key = GetFinalKey(key); //获取带SenparcWeixin:DefaultCache:前缀的Key([DefaultCache]可配置) var list = _cache.HashGetAll(key); var dic = new Dictionary <string, TBag>(); foreach (var hashEntry in list) { var fullKey = key + ":" + hashEntry.Name;//最完整的finalKey(可用于LocalCache),还原完整Key,格式:[命名空间]:[Key] dic[fullKey] = StackExchangeRedisExtensions.Deserialize <TBag>(hashEntry.Value); } return(dic); }
public IBaseContainerBag Get(string key, bool isFullKey = false) { if (string.IsNullOrEmpty(key)) { return(null); } if (!CheckExisted(key, isFullKey)) { return(null); //InsertToCache(key, new ContainerItemCollection()); } //var cacheKey = GetFinalKey(key, isFullKey); var hashKeyAndField = this.GetHashKeyAndField(key, isFullKey); //var value = _cache.StringGet(cacheKey); var value = _cache.HashGet(hashKeyAndField.Key, hashKeyAndField.Field); return(StackExchangeRedisExtensions.Deserialize <IBaseContainerBag>(value)); }