Пример #1
0
        /// <summary>
        ///  listRight的追加
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static long PushListRight(RedisCacheType Type, string Key, string value)
        {
            var db = RedisMananger.GetDatabase((int)Type);

            Key = GetRedisKey(Type, Key);
            return(db.ListRightPush(Key, value));
        }
Пример #2
0
        /// <summary>
        /// 设置Key的过期时间
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static bool SetKeyExpire(RedisCacheType Type, string Key, int ExpireMinutes)
        {
            var db = RedisMananger.GetDatabase((int)Type);

            Key = GetRedisKey(Type, Key);
            return(db.KeyExpire(Key, TimeSpan.FromMinutes(ExpireMinutes)));
        }
Пример #3
0
        /// <summary>
        /// 移除Key的过期时间
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static bool RemoveKeyExpire(RedisCacheType Type, string Key)
        {
            var db = RedisMananger.GetDatabase((int)Type);

            Key = GetRedisKey(Type, Key);
            return(db.KeyPersist(Key));
        }
Пример #4
0
        /// <summary>
        /// Key是否存在
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static bool ExistKey(RedisCacheType Type, string Key)
        {
            var db = RedisMananger.GetDatabase((int)Type);

            Key = GetRedisKey(Type, Key);
            return(db.KeyExists(Key));
        }
Пример #5
0
        /// <summary>
        /// 获取Key的Value
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Type"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static T GetValue <T>(RedisCacheType Type, string Key)
        {
            var db = RedisMananger.GetDatabase((int)Type);

            Key = GetRedisKey(Type, Key);
            string value = db.StringGet(Key);

            return(JsonHelper.Deserialize <T>(value));
        }
Пример #6
0
        /// <summary>
        /// 获取Key的Value
        /// </summary>
        /// <param name="Type"></param>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static string GetValue(RedisCacheType Type, string Key)
        {
            var db = RedisMananger.GetDatabase((int)Type);

            Key = GetRedisKey(Type, Key);
            string value = db.StringGet(Key);

            return(value);
        }
Пример #7
0
 /// <summary>
 /// listLeft的Pop
 /// </summary>
 /// <param name="Type"></param>
 /// <param name="Key"></param>
 /// <returns></returns>
 public static string PopListLeft(RedisCacheType Type, string Key)
 {
     try
     {
         var db = RedisMananger.GetDatabase((int)Type);
         Key = GetRedisKey(Type, Key);
         return(db.ListLeftPop(Key));
     }
     catch (Exception ex)
     {
         logger.Info(ex);
         return(null);
     }
 }
Пример #8
0
        /// <summary>
        /// 设置Key
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="expireSecond"></param>
        /// <returns></returns>
        public static bool SetKey(RedisCacheType Type, string Key, string Value, int ExpireMinutes = 0)
        {
            var db = RedisMananger.GetDatabase((int)Type);

            Key = GetRedisKey(Type, Key);
            if (ExpireMinutes > 0)
            {
                return(db.StringSet(Key, Value, TimeSpan.FromMinutes(ExpireMinutes)));
            }
            else
            {
                return(db.StringSet(Key, Value));
            }
        }
Пример #9
0
        /// <summary>
        ///  设置Key
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="Type"></param>
        /// <param name="Key"></param>
        /// <param name="Value"></param>
        /// <param name="ExpireMinutes"></param>
        /// <returns></returns>
        public static bool SetKey <T>(RedisCacheType Type, string Key, T Value, int ExpireMinutes = 0)
        {
            var db = RedisMananger.GetDatabase((int)Type);

            Key = GetRedisKey(Type, Key);
            string jsonStr = JsonHelper.ToJsonString(Value);

            if (ExpireMinutes > 0)
            {
                return(db.StringSet(Key, jsonStr, TimeSpan.FromMinutes(ExpireMinutes)));
            }
            else
            {
                return(db.StringSet(Key, jsonStr));
            }
        }
Пример #10
0
 /// <summary>
 /// 获取RedisKey
 /// </summary>
 /// <param name="Type"></param>
 /// <param name="Key"></param>
 /// <returns></returns>
 private static string GetRedisKey(RedisCacheType Type, string Key)
 {
     return(Type.ToString() + "_" + Key);
 }