Ejemplo n.º 1
0
        /// <summary>
        /// 添加键值对
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        public static bool StringAdd(string key, string value, TimeSpan timeout = default(TimeSpan))
        {
            try
            {
                RedisDBClient.Add(key, value);
                if (timeout != default(TimeSpan))
                {
                    RedisDBClient.ExpireEntryIn(key, timeout);
                }

                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 批量添加Set集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool AddRange <T>(IEnumerable <T> t, string key, TimeSpan timeout = default(TimeSpan))
            where T : class
        {
            try
            {
                var jsonData = ConvertUtil.ToJson(t);
                RedisDBClient.AddRangeToSet(key, jsonData.ToList());
                if (timeout != default(TimeSpan))
                {
                    RedisDBClient.ExpireEntryIn(key, timeout);
                }

                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }