示例#1
0
 public void PassesMamcachedManager_Set_Success()
 {
     _client.Set("name", "joe", 1000);
     _client.HasKey("name").TestBeTrue();
     _client.Get <string>("name").TestEqual("joe");
     _client.Remove("name");
     _client.HasKey("name").TestBeFalse();
 }
示例#2
0
        private static InkeyResult <string> GetMemcachedResult(string actionType, string sType, string vType, string cacheResult, FormatObjcet formart, List <string> pValueList)
        {
            InkeyResult <string> result = new InkeyResult <string>();
            var cacheManager            = new MemcachedManager(new CacheManagerActionCacheKeyFormat());
            var flag = false;

            switch (actionType)
            {
            case "View":
                object value = string.Empty;
                flag = cacheManager.RawIsSet(formart.Key, out value, pValueList.ToArray());
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "未设置缓存值";
                    return(result);
                }
                else
                {
                    result.Data = value is string?(string)value : value.ToJsonString();
                }
                break;

            case "Update":
                if (cacheManager.RawIsSet(formart.Key, out value, pValueList.ToArray()) && !(value is string))
                {
                    value = JsonConvert.DeserializeObject(cacheResult, value.GetType());
                    flag  = cacheManager.RawSet(formart.Key, value, pValueList.ToArray());
                }
                else
                {
                    flag = cacheManager.RawSet(formart.Key, cacheResult, pValueList.ToArray());
                }
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "请输入JSON";
                    return(result);
                }
                else
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;    //前端需要弹出提示,所有设置这个值
                    result.Desc = "更新成功";
                }
                break;

            case "Delete":
                flag = cacheManager.Remove(formart.Key, pValueList.ToArray());
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "缓存移除失败";
                    return(result);
                }
                break;
            }
            return(result);
        }
示例#3
0
        public void Logout(string token)
        {
            bool flag = cacheManager.Remove(_cache_distribute_token_key, token);

            if (!flag)
            {
                _logger.Error("注销令牌失败,或许多次注销");
            }
        }