public CasResult <bool> AddToRedis <T>(KVRedisType type, string key, string HashField, T value, int DBNum, int Minutes) { var result = new CasResult <bool>(); var strValue = SerializeHelper.ToJson(value); switch (type) { case KVRedisType.StringSet: if (Minutes > 0) { var span = new TimeSpan(DateTime.Now.AddMinutes(Minutes).Ticks); result.Result = SetKey(key, strValue, DBNum, span); } else { result.Result = SetKey(key, strValue, DBNum); } break; case KVRedisType.HashSet: if (!string.IsNullOrEmpty(HashField)) { result.Result = HashSet(key, HashField, strValue, DBNum); } break; case KVRedisType.Set: SetAdd(key, strValue, DBNum); break; case KVRedisType.ListPush: ListLeftPush(key, DBNum, strValue); break; case KVRedisType.StringIncrement: SetKeyInc(key, DBNum); break; } return(result); }
public T GetFromRedis <T>(KVRedisType type, string key, int DBNum) { try { switch (type) { case KVRedisType.StringGet: return(SerializeHelper.Deserialize <T>(StringGet(key, DBNum))); case KVRedisType.ListPop: return(SerializeHelper.Deserialize <T>(ListRightPop(key, DBNum))); } } catch (Exception ex) { //Logger.Exception(ex, "Redis反序列化失败"); } return(default(T)); }
public CasResult <bool> AddToRedis <T>(KVRedisType type, string key, T value, int Minutes) { return(AddToRedis(type, key, string.Empty, value, 0, Minutes)); }
public CasResult <bool> AddToRedis <T>(KVRedisType type, string key, string HashField, T value) { return(AddToRedis(type, key, HashField, value, 0, 0)); }
public T GetFromRedis <T>(KVRedisType type, string key) { return(GetFromRedis <T>(type, key, 0)); }