public string FormatKey(string key, params object[] values) { FormatObjcet formatKey = new FormatObjcet(); formatKey.Key = key; return(formatKey.FormatKey(values)); }
private static InkeyResult <string> GetRedisResult(string actionType, string sType, string vType, string cacheResult, FormatObjcet formart, List <string> pValueList) { InkeyResult <string> result = new InkeyResult <string>(); bool sJsonType = sType == "JSON"; var cacheManager = new RedisManager(new CacheManagerActionCacheKeyFormat()); var flag = false; switch (actionType) { case "View": flag = cacheManager.Exists(formart.Key, pValueList.ToArray()); if (!flag) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "未设置缓存值"; return(result); } if (sJsonType) { result.Data = cacheManager.GetOriginalValue(formart.Key, pValueList.ToArray()); } else { if (string.IsNullOrEmpty(vType)) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "值类型未设置"; return(result); } Type type = Type.GetType(vType); if (type == null) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "值类型未定义,类型:" + vType; return(result); } byte[] oValue = cacheManager.RawGetOriginalValue(formart.Key, pValueList.ToArray()); object value = BinarySerializerManager.BinaryDeSerialize(oValue); result.Data = value.ToJsonString(); } break; case "Update": flag = cacheManager.Exists(formart.Key, pValueList.ToArray()); if (!flag) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "未设置缓存值"; return(result); } if (sJsonType) { flag = cacheManager.OriginalValueAdd(formart.Key, cacheResult, pValueList.ToArray()); if (!flag) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "更新失败"; return(result); } } else { if (string.IsNullOrEmpty(vType)) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "值类型未设置"; return(result); } Type type = Type.GetType(vType); if (type == null) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "值类型未定义,类型:" + vType; return(result); } var oValue = JsonSerializerManager.JsonDeserialize(cacheResult, type); if (oValue == null) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "json格式错误,类型:" + vType; return(result); } else { var value = BinarySerializerManager.BinarySerialize(oValue); flag = cacheManager.RawOriginalValueAdd(formart.Key, value, pValueList.ToArray()); if (!flag) { result.Code = InkeyErrorCodes.CommonBusinessFailure; result.Desc = "更新失败"; return(result); } } } 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); }
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); }