(精华)2020年8月15日 redis数据库 StackExchange.Redis封装源码(C#版)

首先nuget:

  1. ServiceStack.Redis
  2. ServiceStack.Common
  3. ServiceStack.interfaces
  4. ServiceStack.Text

基本版

public sealed class RedisConfigInfo
    {
        /// 
        /// 可写的Redis链接地址
        /// format:ip1,ip2
        /// 
        /// 默认6379端口
        /// 
        public string WriteServerList = "127.0.0.1:6379";
        /// 
        /// 可读的Redis链接地址
        /// format:ip1,ip2
        /// 
        public string ReadServerList = "127.0.0.1:6379";
        /// 
        /// 最大写链接数
        /// 
        public int MaxWritePoolSize = 60;
        /// 
        /// 最大读链接数
        /// 
        public int MaxReadPoolSize = 60;
        /// 
        /// 本地缓存到期时间,单位:秒
        /// 
        public int LocalCacheTime = 180;
        /// 
        /// 自动重启
        /// 
        public bool AutoStart = true;
        /// 
        /// 是否记录日志,该设置仅用于排查redis运行时出现的问题,
        /// 如redis工作正常,请关闭该项
        /// 
        public bool RecordeLog = false;
    }

/// 
    /// Redis管理中心
    /// 
    public class RedisManager
    {
        /// 
        /// redis配置文件信息
        /// 
        private static RedisConfigInfo RedisConfigInfo = new RedisConfigInfo();

        /// 
        /// Redis客户端池化管理
        /// 
        private static PooledRedisClientManager prcManager;

        /// 
        /// 静态构造方法,初始化链接池管理对象
        /// 
        static RedisManager()
        {
            CreateManager();
        }

        /// 
        /// 创建链接池管理对象
        /// 
        private static void CreateManager()
        {
            string[] WriteServerConStr = RedisConfigInfo.WriteServerList.Split(',');
            string[] ReadServerConStr = RedisConfigInfo.ReadServerList.Split(',');
            prcManager = new PooledRedisClientManager(ReadServerConStr, WriteServerConStr,
                             new RedisClientManagerConfig
                             {
                                 MaxWritePoolSize = RedisConfigInfo.MaxWritePoolSize,
                                 MaxReadPoolSize = RedisConfigInfo.MaxReadPoolSize,
                                 AutoStart = RedisConfigInfo.AutoStart,
                             });
        }

        /// 
        /// 客户端缓存操作对象
        /// 
        public static IRedisClient GetClient()
        {
            return prcManager.GetClient();
        }
    }

 /// 
    /// RedisBase类,是redis操作的基类,继承自IDisposable接口,主要用于释放内存
    /// 
    public abstract class RedisBase : IDisposable
    {
        public IRedisClient iClient { get; private set; }
        /// 
        /// 构造时完成链接的打开
        /// 
        public RedisBase()
        {
            iClient = RedisManager.GetClient();
        }

        //public static IRedisClient iClient { get; private set; }
        //static RedisBase()
        //{
        //    iClient = RedisManager.GetClient();
        //}


        private bool _disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                if (disposing)
                {
                    iClient.Dispose();
                    iClient = null;
                }
            }
            this._disposed = true;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        public void Transcation()
        {
            using (IRedisTransaction irt = this.iClient.CreateTransaction())
            {
                try
                {
                    irt.QueueCommand(r => r.Set("key", 20));
                    irt.QueueCommand(r => r.Increment("key", 1));
                    irt.Commit(); // 提交事务
                }
                catch (Exception ex)
                {
                    irt.Rollback();
                    throw ex;
                }
            }
        }


        /// 
        /// 清除全部数据 请小心
        /// 
        public virtual void FlushAll()
        {
            iClient.FlushAll();
        }

        /// 
        /// 保存数据DB文件到硬盘
        /// 
        public void Save()
        {
            iClient.Save();//阻塞式save
        }

        /// 
        /// 异步保存数据DB文件到硬盘
        /// 
        public void SaveAsync()
        {
            iClient.SaveAsync();//异步save
        }
    }

服务层:五大数据结构

public class RedisHashService : RedisBase
    {
        #region 添加
        /// 
        /// 向hashid集合中添加key/value
        ///        
        public bool SetEntryInHash(string hashid, string key, string value)
        {
            return base.iClient.SetEntryInHash(hashid, key, value);
        }
        /// 
        /// 如果hashid集合中存在key/value则不添加返回false,
        /// 如果不存在在添加key/value,返回true
        /// 
        public bool SetEntryInHashIfNotExists(string hashid, string key, string value)
        {
            return base.iClient.SetEntryInHashIfNotExists(hashid, key, value);
        }
        /// 
        /// 存储对象T t到hash集合中
        /// 需要包含Id,然后用Id获取
        /// 
        public void StoreAsHash<T>(T t)
        {
            base.iClient.StoreAsHash<T>(t);
        }
        #endregion

        #region 获取
        /// 
        /// 获取对象T中ID为id的数据。
        /// 
        public T GetFromHash<T>(object id)
        {
            return base.iClient.GetFromHash<T>(id);
        }
        /// 
        /// 获取所有hashid数据集的key/value数据集合
        /// 
        public Dictionary<string, string> GetAllEntriesFromHash(string hashid)
        {
            return base.iClient.GetAllEntriesFromHash(hashid);
        }
        /// 
        /// 获取hashid数据集中的数据总数
        /// 
        public long GetHashCount(string hashid)
        {
            return base.iClient.GetHashCount(hashid);
        }
        /// 
        /// 获取hashid数据集中所有key的集合
        /// 
        public List<string> GetHashKeys(string hashid)
        {
            return base.iClient.GetHashKeys(hashid);
        }
        /// 
        /// 获取hashid数据集中的所有value集合
        /// 
        public List<string> GetHashValues(string hashid)
        {
            return base.iClient.GetHashValues(hashid);
        }
        /// 
        /// 获取hashid数据集中,key的value数据
        /// 
        public string GetValueFromHash(string hashid, string key)
        {
            return base.iClient.GetValueFromHash(hashid, key);
        }
        /// 
        /// 获取hashid数据集中,多个keys的value集合
        /// 
        public List<string> GetValuesFromHash(string hashid, string[] keys)
        {
            return base.iClient.GetValuesFromHash(hashid, keys);
        }
        #endregion

        #region 删除
        /// 
        /// 删除hashid数据集中的key数据
        /// 
        public bool RemoveEntryFromHash(string hashid, string key)
        {
            return base.iClient.RemoveEntryFromHash(hashid, key);
        }
        #endregion

        #region 其它
        /// 
        /// 判断hashid数据集中是否存在key的数据
        /// 
        public bool HashContainsEntry(string hashid, string key)
        {
            return base.iClient.HashContainsEntry(hashid, key);
        }
        /// 
        /// 给hashid数据集key的value加countby,返回相加后的数据
        /// 
        public double IncrementValueInHash(string hashid, string key, double countBy)
        {
            return base.iClient.IncrementValueInHash(hashid, key, countBy);
        }
        #endregion
    }

 public class RedisListService : RedisBase
    {
        #region 赋值
        /// 
        /// 从左侧向list中添加值
        /// 
        public void LPush(string key, string value)
        {
            base.iClient.PushItemToList(key, value);
        }
        /// 
        /// 从左侧向list中添加值,并设置过期时间
        /// 
        public void LPush(string key, string value, DateTime dt)
        {

            base.iClient.PushItemToList(key, value);
            base.iClient.ExpireEntryAt(key, dt);
        }
        /// 
        /// 从左侧向list中添加值,设置过期时间
        /// 
        public void LPush(string key, string value, TimeSpan sp)
        {
            base.iClient.PushItemToList(key, value);
            base.iClient.ExpireEntryIn(key, sp);
        }
        /// 
        /// 从右侧向list中添加值
        /// 
        public void RPush(string key, string value)
        {
            base.iClient.PrependItemToList(key, value);
        }
        /// 
        /// 从右侧向list中添加值,并设置过期时间
        ///     
        public void RPush(string key, string value, DateTime dt)
        {
            base.iClient.PrependItemToList(key, value);
            base.iClient.ExpireEntryAt(key, dt);
        }
        /// 
        /// 从右侧向list中添加值,并设置过期时间
        ///         
        public void RPush(string key, string value, TimeSpan sp)
        {
            base.iClient.PrependItemToList(key, value);
            base.iClient.ExpireEntryIn(key, sp);
        }
        /// 
        /// 添加key/value
        ///      
        public void Add(string key, string value)
        {
            base.iClient.AddItemToList(key, value);
        }
        /// 
        /// 添加key/value ,并设置过期时间
        ///   
        public void Add(string key, string value, DateTime dt)
        {
            base.iClient.AddItemToList(key, value);
            base.iClient.ExpireEntryAt(key, dt);
        }
        /// 
        /// 添加key/value。并添加过期时间
        ///   
        public void Add(string key, string value, TimeSpan sp)
        {
            base.iClient.AddItemToList(key, value);
            base.iClient.ExpireEntryIn(key, sp);
        }
        /// 
        /// 为key添加多个值
        ///   
        public void Add(string key, List<string> values)
        {
            base.iClient.AddRangeToList(key, values);
        }
        /// 
        /// 为key添加多个值,并设置过期时间
        ///   
        public void Add(string key, List<string> values, DateTime dt)
        {
            base.iClient.AddRangeToList(key, values);
            base.iClient.ExpireEntryAt(key, dt);
        }
        /// 
        /// 为key添加多个值,并设置过期时间
        ///   
        public void Add(string key, List<string> values, TimeSpan sp)
        {
            base.iClient.AddRangeToList(key, values);
            base.iClient.ExpireEntryIn(key, sp);
        }
        #endregion

        #region 获取值
        /// 
        /// 获取list中key包含的数据数量
        ///   
        public long Count(string key)
        {
            return base.iClient.GetListCount(key);
        }
        /// 
        /// 获取key包含的所有数据集合
        ///   
        public List<string> Get(string key)
        {
            return base.iClient.GetAllItemsFromList(key);
        }
        /// 
        /// 获取key中下标为star到end的值集合 
        ///   
        public List<string> Get(string key, int star, int end)
        {
            return base.iClient.GetRangeFromList(key, star, end);
        }
        #endregion

        #region 阻塞命令
        /// 
        ///  阻塞命令:从list为key的尾部移除一个值,并返回移除的值,阻塞时间为sp
        ///   
        public string BlockingPopItemFromList(string key, TimeSpan? sp)
        {
            return base.iClient.BlockingPopItemFromList(key, sp);
        }
        /// 
        ///  阻塞命令:从多个list中尾部移除一个值,并返回移除的值&key,阻塞时间为sp
        ///   
        public ItemRef BlockingPopItemFromLists(string[] keys, TimeSpan? sp)
        {
            return base.iClient.BlockingPopItemFromLists(keys, sp);
        }


        /// 
        ///  阻塞命令:从list中keys的尾部移除一个值,并返回移除的值,阻塞时间为sp
        ///   
        public string BlockingDequeueItemFromList(string key, TimeSpan? sp)
        {
            return base.iClient.BlockingDequeueItemFromList(key, sp);
        }

        /// 
        /// 阻塞命令:从多个list中尾部移除一个值,并返回移除的值&key,阻塞时间为sp
        ///   
        public ItemRef BlockingDequeueItemFromLists(string[] keys, TimeSpan? sp)
        {
            return base.iClient.BlockingDequeueItemFromLists(keys, sp);
        }

        /// 
        /// 阻塞命令:从list中一个fromkey的尾部移除一个值,添加到另外一个tokey的头部,并返回移除的值,阻塞时间为sp
        ///   
        public string BlockingPopAndPushItemBetweenLists(string fromkey, string tokey, TimeSpan? sp)
        {
            return base.iClient.BlockingPopAndPushItemBetweenLists(fromkey, tokey, sp);
        }
        #endregion

        #region 删除
        /// 
        /// 从尾部移除数据,返回移除的数据
        ///   
        public string PopItemFromList(string key)
        {
            var sa = base.iClient.CreateSubscription();
            return base.iClient.PopItemFromList(key);
        }
        /// 
        /// 从尾部移除数据,返回移除的数据
        ///   
        public string DequeueItemFromList(string key)
        {
            return base.iClient.DequeueItemFromList(key);
        }

        /// 
        /// 移除list中,key/value,与参数相同的值,并返回移除的数量
        ///   
        public long RemoveItemFromList(string key, string value)
        {
            return base.iClient.RemoveItemFromList(key, value);
        }
        /// 
        /// 从list的尾部移除一个数据,返回移除的数据
        ///   
        public string RemoveEndFromList(string key)
        {
            return base.iClient.RemoveEndFromList(key);
        }
        /// 
        /// 从list的头部移除一个数据,返回移除的值
        ///   
        public string RemoveStartFromList(string key)
        {
            return base.iClient.RemoveStartFromList(key);
        }
        #endregion

        #region 其它
        /// 
        /// 从一个list的尾部移除一个数据,添加到另外一个list的头部,并返回移动的值
        ///   
        public string PopAndPushItemBetweenLists(string fromKey, string toKey)
        {
            return base.iClient.PopAndPushItemBetweenLists(fromKey, toKey);
        }
        #endregion

        #region 发布订阅
        public void Publish(string channel, string message)
        {
            base.iClient.PublishMessage(channel, message);
        }

        public void Subscribe(string channel, Action<string, string, IRedisSubscription> actionOnMessage)
        {
            var subscription = base.iClient.CreateSubscription();
            subscription.OnSubscribe = c =>
            {
                Console.WriteLine($"订阅频道{c}");
                Console.WriteLine();
            };
            //取消订阅
            subscription.OnUnSubscribe = c =>
            {
                Console.WriteLine($"取消订阅 {c}");
                Console.WriteLine();
            };
            subscription.OnMessage += (c, s) =>
            {
                actionOnMessage(c, s, subscription);
            };
            Console.WriteLine($"开始启动监听 {channel}");
            subscription.SubscribeToChannels(channel); //blocking
        }

        public void UnSubscribeFromChannels(string channel)
        {
            var subscription = base.iClient.CreateSubscription();
            subscription.UnSubscribeFromChannels(channel);
        }
        #endregion
    }

public class RedisSetService : RedisBase
    {
        #region 添加
        /// 
        /// key集合中添加value值
        /// 
        public void Add(string key, string value)
        {
            base.iClient.AddItemToSet(key, value);
        }
        /// 
        /// key集合中添加list集合
        /// 
        public void Add(string key, List<string> list)
        {
            base.iClient.AddRangeToSet(key, list);

        }
        #endregion

        #region 获取
        /// 
        /// 随机获取key集合中的一个值
        /// 
        public string GetRandomItemFromSet(string key)
        {
            return base.iClient.GetRandomItemFromSet(key);
        }
        /// 
        /// 获取key集合值的数量
        /// 
        public long GetCount(string key)
        {
            return base.iClient.GetSetCount(key);
        }
        /// 
        /// 获取所有key集合的值
        /// 
        public HashSet<string> GetAllItemsFromSet(string key)
        {
            return base.iClient.GetAllItemsFromSet(key);
        }
        #endregion

        #region 删除
        /// 
        /// 随机删除key集合中的一个值
        /// 
        public string RandomRemoveItemFromSet(string key)
        {
            return base.iClient.PopItemFromSet(key);
        }
        /// 
        /// 删除key集合中的value
        /// 
        public void RemoveItemFromSet(string key, string value)
        {
            base.iClient.RemoveItemFromSet(key, value);
        }
        #endregion

        #region 其它
        /// 
        /// 从fromkey集合中移除值为value的值,并把value添加到tokey集合中
        /// 
        public void MoveBetweenSets(string fromkey, string tokey, string value)
        {
            base.iClient.MoveBetweenSets(fromkey, tokey, value);
        }
        /// 
        /// 返回keys多个集合中的并集,返还hashset
        /// 
        public HashSet<string> GetUnionFromSets(params string[] keys)
        {
            return base.iClient.GetUnionFromSets(keys);
        }
        /// 
        /// 返回keys多个集合中的交集,返还hashset
        /// 
        public HashSet<string> GetIntersectFromSets(params string[] keys)
        {
            return base.iClient.GetIntersectFromSets(keys);
        }
        /// 
        /// 返回keys多个集合中的差集,返还hashset
        /// 
        /// 原集合
        /// 其他集合
        /// 出现在原集合,但不包含在其他集合
        public HashSet<string> GetDifferencesFromSet(string fromKey, params string[] keys)
        {
            return base.iClient.GetDifferencesFromSet(fromKey,keys);
        }
        /// 
        /// keys多个集合中的并集,放入newkey集合中
        /// 
        public void StoreUnionFromSets(string newkey, string[] keys)
        {
            base.iClient.StoreUnionFromSets(newkey, keys);
        }
        /// 
        /// 把fromkey集合中的数据与keys集合中的数据对比,fromkey集合中不存在keys集合中,则把这些不存在的数据放入newkey集合中
        /// 
        public void StoreDifferencesFromSet(string newkey, string fromkey, string[] keys)
        {
            base.iClient.StoreDifferencesFromSet(newkey, fromkey, keys);
        }
        #endregion
    }

 public class RedisStringService : RedisBase
    {
        #region 赋值
        /// 
        /// 设置key的value
        /// 
        public bool Set<T>(string key, T value)
        {
            return base.iClient.Set<T>(key, value);
        }
        /// 
        /// 设置key的value并设置过期时间
        /// 
        public bool Set<T>(string key, T value, DateTime dt)
        {
            return base.iClient.Set<T>(key, value, dt);
        }
        /// 
        /// 设置key的value并设置过期时间
        /// 
        public bool Set<T>(string key, T value, TimeSpan sp)
        {
            return base.iClient.Set<T>(key, value, sp);
        }
        /// 
        /// 设置多个key/value
        /// 
        public void Set(Dictionary<string, string> dic)
        {
            base.iClient.SetAll(dic);
        }

        #endregion

        #region 追加
        /// 
        /// 在原有key的value值之后追加value,没有就新增一项
        /// 
        public long Append(string key, string value)
        {
            return base.iClient.AppendToValue(key, value);
        }
        #endregion

        #region 获取值
        /// 
        /// 获取key的value值
        /// 
        public string Get(string key)
        {
            return base.iClient.GetValue(key);
        }
        /// 
        /// 获取多个key的value值
        /// 
        public List<string> Get(List<string> keys)
        {
            return base.iClient.GetValues(keys);
        }
        /// 
        /// 获取多个key的value值
        /// 
        public List<T> Get<T>(List<string> keys)
        {
            return base.iClient.GetValues<T>(keys);
        }
        #endregion

        #region 获取旧值赋上新值
        /// 
        /// 获取旧值赋上新值
        /// 
        public string GetAndSetValue(string key, string value)
        {
            return base.iClient.GetAndSetValue(key, value);
        }
        #endregion

        #region 辅助方法
        /// 
        /// 获取值的长度
        /// 
        public long GetLength(string key)
        {
            return base.iClient.GetStringCount(key);
        }
        /// 
        /// 自增1,返回自增后的值
        /// 
        public long Incr(string key)
        {
            return base.iClient.IncrementValue(key);
        }
        /// 
        /// 自增count,返回自增后的值
        /// 
        public long IncrBy(string key, int count)
        {
            return base.iClient.IncrementValueBy(key, count);
        }
        /// 
        /// 自减1,返回自减后的值
        /// 
        public long Decr(string key)
        {
            return base.iClient.DecrementValue(key);
        }
        /// 
        /// 自减count ,返回自减后的值
        /// 
        /// 
        /// 
        /// 
        public long DecrBy(string key, int count)
        {
            return base.iClient.DecrementValueBy(key, count);
        }
        #endregion
    }

public class RedisZSetService : RedisBase
    {
        #region 添加
        /// 
        /// 添加key/value,默认分数是从1.多*10的9次方以此递增的,自带自增效果
        /// 
        public bool Add(string key, string value)
        {
            return base.iClient.AddItemToSortedSet(key, value);
        }
        /// 
        /// 添加key/value,并设置value的分数
        /// 
        public bool AddItemToSortedSet(string key, string value, double score)
        {
            return base.iClient.AddItemToSortedSet(key, value, score);
        }
        /// 
        /// 为key添加values集合,values集合中每个value的分数设置为score
        /// 
        public bool AddRangeToSortedSet(string key, List<string> values, double score)
        {
            return base.iClient.AddRangeToSortedSet(key, values, score);
        }
        /// 
        /// 为key添加values集合,values集合中每个value的分数设置为score
        /// 
        public bool AddRangeToSortedSet(string key, List<string> values, long score)
        {
            return base.iClient.AddRangeToSortedSet(key, values, score);
        }
        #endregion

        #region 获取
        /// 
        /// 获取key的所有集合
        /// 
        public List<string> GetAll(string key)
        {
            return base.iClient.GetAllItemsFromSortedSet(key);
        }
        /// 
        /// 获取key的所有集合,倒叙输出
        /// 
        public List<string> GetAllDesc(string key)
        {
            return base.iClient.GetAllItemsFromSortedSetDesc(key);
        }
        /// 
        /// 获取集合,带分数
        /// 
        public IDictionary<string, double> GetAllWithScoresFromSortedSet(string key)
        {
            return base.iClient.GetAllWithScoresFromSortedSet(key);
        }
        /// 
        /// 获取key为value的下标值
        /// 
        public long GetItemIndexInSortedSet(string key, string value)
        {
            return base.iClient.GetItemIndexInSortedSet(key, value);
        }
        /// 
        /// 倒叙排列获取key为value的下标值
        /// 
        public long GetItemIndexInSortedSetDesc(string key, string value)
        {
            return base.iClient.GetItemIndexInSortedSetDesc(key, value);
        }
        /// 
        /// 获取key为value的分数
        /// 
        public double GetItemScoreInSortedSet(string key, string value)
        {
            return base.iClient.GetItemScoreInSortedSet(key, value);
        }
        /// 
        /// 获取key所有集合的数据总数
        /// 
        public long GetSortedSetCount(string key)
        {
            return base.iClient.GetSortedSetCount(key);
        }
        /// 
        /// key集合数据从分数为fromscore到分数为toscore的数据总数
        /// 
        public long GetSortedSetCount(string key, double fromScore, double toScore)
        {
            return base.iClient.GetSortedSetCount(key, fromScore, toScore);
        }
        /// 
        /// 获取key集合从高分到低分排序数据,分数从fromscore到分数为toscore的数据
        /// 
        public List<string> GetRangeFromSortedSetByHighestScore(string key, double fromscore, double toscore)
        {
            return base.iClient.GetRangeFromSortedSetByHighestScore(key, fromscore, toscore);
        }
        /// 
        /// 获取key集合从低分到高分排序数据,分数从fromscore到分数为toscore的数据
        /// 
        public List<string> GetRangeFromSortedSetByLowestScore(string key, double fromscore, double toscore)
        {
            return base.iClient.GetRangeFromSortedSetByLowestScore(key, fromscore, toscore);
        }
        /// 
        /// 获取key集合从高分到低分排序数据,分数从fromscore到分数为toscore的数据,带分数
        /// 
        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string key, double fromscore, double toscore)
        {
            return base.iClient.GetRangeWithScoresFromSortedSetByHighestScore(key, fromscore, toscore);
        }
        /// 
        ///  获取key集合从低分到高分排序数据,分数从fromscore到分数为toscore的数据,带分数
        /// 
        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string key, double fromscore, double toscore)
        {
            return base.iClient.GetRangeWithScoresFromSortedSetByLowestScore(key, fromscore, toscore);
        }
        /// 
        ///  获取key集合数据,下标从fromRank到分数为toRank的数据
        /// 
        public List<string> GetRangeFromSortedSet(string key, int fromRank, int toRank)
        {
            return base.iClient.GetRangeFromSortedSet(key, fromRank, toRank);
        }
        /// 
        /// 获取key集合倒叙排列数据,下标从fromRank到分数为toRank的数据
        /// 
        public List<string> GetRangeFromSortedSetDesc(string key, int fromRank, int toRank)
        {
            return base.iClient.GetRangeFromSortedSetDesc(key, fromRank, toRank);
        }
        /// 
        /// 获取key集合数据,下标从fromRank到分数为toRank的数据,带分数
        /// 
        public IDictionary<string, double> GetRangeWithScoresFromSortedSet(string key, int fromRank, int toRank)
        {
            return base.iClient.GetRangeWithScoresFromSortedSet(key, fromRank, toRank);
        }
        /// 
        ///  获取key集合倒叙排列数据,下标从fromRank到分数为toRank的数据,带分数
        /// 
        public IDictionary<string, double> GetRangeWithScoresFromSortedSetDesc(string key, int fromRank, int toRank)
        {
            return base.iClient.GetRangeWithScoresFromSortedSetDesc(key, fromRank, toRank);
        }
        #endregion

        #region 删除
        /// 
        /// 删除key为value的数据
        /// 
        public bool RemoveItemFromSortedSet(string key, string value)
        {
            return base.iClient.RemoveItemFromSortedSet(key, value);
        }
        /// 
        /// 删除下标从minRank到maxRank的key集合数据
        /// 
        public long RemoveRangeFromSortedSet(string key, int minRank, int maxRank)
        {
            return base.iClient.RemoveRangeFromSortedSet(key, minRank, maxRank);
        }
        /// 
        /// 删除分数从fromscore到toscore的key集合数据
        /// 
        public long RemoveRangeFromSortedSetByScore(string key, double fromscore, double toscore)
        {
            return base.iClient.RemoveRangeFromSortedSetByScore(key, fromscore, toscore);
        }
        /// 
        /// 删除key集合中分数最大的数据
        /// 
        public string PopItemWithHighestScoreFromSortedSet(string key)
        {
            return base.iClient.PopItemWithHighestScoreFromSortedSet(key);
        }
        /// 
        /// 删除key集合中分数最小的数据
        /// 
        public string PopItemWithLowestScoreFromSortedSet(string key)
        {
            return base.iClient.PopItemWithLowestScoreFromSortedSet(key);
        }
        #endregion

        #region 其它
        /// 
        /// 判断key集合中是否存在value数据
        /// 
        public bool SortedSetContainsItem(string key, string value)
        {
            return base.iClient.SortedSetContainsItem(key, value);
        }
        /// 
        /// 为key集合值为value的数据,分数加scoreby,返回相加后的分数
        /// 
        public double IncrementItemInSortedSet(string key, string value, double scoreBy)
        {
            return base.iClient.IncrementItemInSortedSet(key, value, scoreBy);
        }
        /// 
        /// 获取keys多个集合的交集,并把交集添加的newkey集合中,返回交集数据的总数
        /// 
        public long StoreIntersectFromSortedSets(string newkey, string[] keys)
        {
            return base.iClient.StoreIntersectFromSortedSets(newkey, keys);
        }
        /// 
        /// 获取keys多个集合的并集,并把并集数据添加到newkey集合中,返回并集数据的总数
        /// 
        public long StoreUnionFromSortedSets(string newkey, string[] keys)
        {
            return base.iClient.StoreUnionFromSortedSets(newkey, keys);
        }
        #endregion
    }

扩展版

/// 
    /// Redis基本信息初始化辅助类
    /// 
    internal class RedisManager
    {
        //private static LogHelper log = LogHelper.LogInterface();
        private static readonly object Locker = new object();
        private static ConnectionMultiplexer _instance;
        private static readonly ConcurrentDictionary<string, ConnectionMultiplexer> ConnectionCache = new ConcurrentDictionary<string, ConnectionMultiplexer>();
        /// 
        /// Redis保存的Key前缀,会自动添加到指定的Key名称前
        /// 
        internal static readonly string RedisSysCustomKey = ConfigurationManager.AppSettings["RedisSysCustomKey"];
        /// 
        /// 当前连接的Redis中的DataBase索引,默认0-16,可以在service.conf配置,最高64
        /// 
        internal static readonly int RedisDataBaseIndex = int.Parse(ConfigurationManager.AppSettings["RedisDataBaseIndex"]);
        /// 
        /// 当前连接的Redis中连接字符串,格式为:127.0.0.1:6379,allowadmin=true,passowrd=pwd
        /// 
        internal static readonly string RedisHostConnection = ConfigurationManager.AppSettings["RedisHostConnection"];

        /// 
        /// 单例获取
        /// 
        public static ConnectionMultiplexer Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (Locker)
                    {
                        if (_instance == null || !_instance.IsConnected)
                        {
                            _instance = GetManager();
                        }
                    }
                }
                return _instance;
            }
        }

        /// 
        /// 缓存获取
        /// 
        /// 
        /// 
        public static ConnectionMultiplexer GetConnectionMultiplexer(string connectionString)
        {
            if (!ConnectionCache.ContainsKey(connectionString))
            {
                ConnectionCache[connectionString] = GetManager(connectionString);
            }
            return ConnectionCache[connectionString];
        }

        /// 
        /// 内部方法,获取Redis连接
        /// 
        /// 
        /// 
        private static ConnectionMultiplexer GetManager(string connectionString = null)
        {
            connectionString = connectionString ?? RedisHostConnection;
            var connect = ConnectionMultiplexer.Connect(connectionString);

            //注册如下事件
            connect.ConnectionFailed += MuxerConnectionFailed;
            connect.ConnectionRestored += MuxerConnectionRestored;
            connect.ErrorMessage += MuxerErrorMessage;
            connect.ConfigurationChanged += MuxerConfigurationChanged;
            connect.HashSlotMoved += MuxerHashSlotMoved;
            connect.InternalError += MuxerInternalError;

            return connect;
        }

        #region 事件

        /// 
        /// 配置更改时
        /// 
        /// 
        /// 
        private static void MuxerConfigurationChanged(object sender, EndPointEventArgs e)
        {
            //log.InfoAsync($"Configuration changed: {e.EndPoint}");
        }

        /// 
        /// 发生错误时
        /// 
        /// 
        /// 
        private static void MuxerErrorMessage(object sender, RedisErrorEventArgs e)
        {
            //log.InfoAsync($"ErrorMessage: {e.Message}");
        }

        /// 
        /// 重新建立连接之前的错误
        /// 
        /// 
        /// 
        private static void MuxerConnectionRestored(object sender, ConnectionFailedEventArgs e)
        {
            //log.InfoAsync($"ConnectionRestored: {e.EndPoint}");
        }

        /// 
        /// 连接失败 , 如果重新连接成功你将不会收到这个通知
        /// 
        /// 
        /// 
        private static void MuxerConnectionFailed(object sender, ConnectionFailedEventArgs e)
        {
            //log.InfoAsync($"重新连接:Endpoint failed: {e.EndPoint},  {e.FailureType} , {(e.Exception == null ? "" : e.Exception.Message)}");
        }

        /// 
        /// 更改集群
        /// 
        /// 
        /// 
        private static void MuxerHashSlotMoved(object sender, HashSlotMovedEventArgs e)
        {
            //log.InfoAsync($"HashSlotMoved:NewEndPoint{e.NewEndPoint}, OldEndPoint{e.OldEndPoint}");
        }

        /// 
        /// redis类库错误
        /// 
        /// 
        /// 
        private static void MuxerInternalError(object sender, InternalErrorEventArgs e)
        {
            //log.InfoAsync($"InternalError:Message{ e.Exception.Message}");
        }

        #endregion 事件
    }
/// 
    /// Redis操作方法基础类
    /// 
    public abstract class RedisBase : IDisposable
    {

        #region 属性字段
        /// 
        /// 网站Redis 系统自定义Key前缀
        /// 
        protected string CustomKey = RedisManager.RedisSysCustomKey;
        /// 
        /// 网站Redis 链接字符串
        /// 
        protected readonly ConnectionMultiplexer _conn;
        /// 
        /// Redis操作对象
        /// 
        protected readonly IDatabase redis = null;
        #endregion

        #region 构造函数
        /// 
        /// 初始化Redis操作方法基础类
        /// 
        /// 操作的数据库索引0-64(需要在conf文件中配置)
        protected RedisBase(int? dbNum = null)
        {
            _conn = RedisManager.Instance;
            if (_conn != null)
            {
                redis = _conn.GetDatabase(dbNum ?? RedisManager.RedisDataBaseIndex);
            }
            else
            {
                throw new ArgumentNullException("Redis连接初始化失败");
            }
        }

        private bool _disposed = false;
        protected virtual void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                if (disposing)
                {
                    _conn.Dispose();
                }
            }
            this._disposed = true;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion 构造函数

        #region 外部调用静态方法
        /// 
        /// 获取Redis的String数据类型操作辅助方法类
        /// 
        /// 
        public static RedisStringService StringService => new RedisStringService();
        /// 
        /// 获取Redis的Hash数据类型操作辅助方法类
        /// 
        /// 
        public static RedisHashService HashService => new RedisHashService();
        /// 
        /// 获取Redis的List数据类型操作辅助方法类
        /// 
        /// 
        public static RedisListService ListService => new RedisListService();
        /// 
        /// 获取Redis的Set无序集合数据类型操作辅助方法类
        /// 
        /// 
        public static RedisSetService SetService => new RedisSetService();
        /// 
        /// 获取Redis的SortedSet(ZSet)有序集合数据类型操作辅助方法类
        /// 
        /// 
        public static RedisSortedSetService SortedSetService => new RedisSortedSetService();

        #endregion

        #region 公共操作方法

        #region 不建议公开这些方法,如果项目中用不到,建议注释或者删除
        /// 
        /// 获取Redis事务对象
        /// 
        /// 
        public ITransaction CreateTransaction() => redis.CreateTransaction();

        /// 
        /// 获取Redis服务和常用操作对象
        /// 
        /// 
        public IDatabase GetDatabase() => redis;

        /// 
        /// 获取Redis服务
        /// 
        /// 
        /// 
        public IServer GetServer(string hostAndPort) => _conn.GetServer(hostAndPort);

        /// 
        /// 执行Redis事务
        /// 
        /// 
        /// 
        public bool RedisTransaction(Action<ITransaction> act)
        {
            var tran = redis.CreateTransaction();
            act.Invoke(tran);
            bool committed = tran.Execute();
            return committed;
        }
        /// 
        /// Redis锁
        /// 
        /// 
        /// 锁住时间
        public void RedisLockTake(Action act, TimeSpan ts)
        {
            RedisValue token = Environment.MachineName;
            string lockKey = "lock_LockTake";
            if (redis.LockTake(lockKey, token, ts))
            {
                try
                {
                    act();
                }
                finally
                {
                    redis.LockRelease(lockKey, token);
                }
            }
        }
        #endregion 其他

        #region 常用Key操作
        /// 
        /// 设置前缀
        /// 
        /// 
        public void SetSysCustomKey(string customKey) => CustomKey = customKey;

        /// 
        /// 组合缓存Key名称
        /// 
        /// 
        /// 
        public string AddSysCustomKey(string oldKey) => $"{CustomKey}_{oldKey}";

        #region 同步方法

        /// 
        /// 删除单个key
        /// 
        /// 要删除的key
        /// 是否删除成功
        public bool KeyDelete(string key)
        {
            key = AddSysCustomKey(key);
            return redis.KeyDelete(key);
        }

        /// 
        /// 删除多个key
        /// 
        /// 要删除的key集合
        /// 成功删除的个数
        public long KeyDelete(params string[] keys)
        {
            RedisKey[] newKeys = keys.Select(o => (RedisKey)AddSysCustomKey(o)).ToArray();
            return redis.KeyDelete(newKeys);
        }

        /// 
        /// 清空当前DataBase中所有Key
        /// 
        public void KeyFulsh()
        {
            //直接执行清除命令
            redis.Execute("FLUSHDB");
        }

        /// 
        /// 判断key是否存在
        /// 
        /// 要判断的key
        /// 
        public bool KeyExists(string key)
        {
            key = AddSysCustomKey(key);
            return redis.KeyExists(key);
        }

        /// 
        /// 重新命名key
        /// 
        /// 就的redis key
        /// 新的redis key
        /// 
        public bool KeyRename(string key, string newKey)
        {
            key = AddSysCustomKey(key);
            newKey = AddSysCustomKey(newKey);
            return redis.KeyRename(key, newKey);
        }

        /// 
        /// 设置Key的过期时间
        /// 
        /// redis key
        /// 过期时间
        /// 
        public bool KeyExpire(string key, TimeSpan? expiry = default(TimeSpan?))
        {
            key = AddSysCustomKey(key);
            return redis.KeyExpire(key, expiry);
        }


        #endregion

        #region 异步方法

        /// 
        /// 删除单个key
        /// 
        /// 要删除的key
        /// 是否删除成功
        public async Task<bool> KeyDeleteAsync(string key)
        {
            key = AddSysCustomKey(key);
            return await redis.KeyDeleteAsync(key);
        }

        /// 
        /// 删除多个key
        /// 
        /// 要删除的key集合
        /// 成功删除的个数
        public async Task<long> KeyDeleteAsync(params string[] keys)
        {
            RedisKey[] newKeys = keys.Select(o => (RedisKey)AddSysCustomKey(o)).ToArray();
            return await redis.KeyDeleteAsync(newKeys);
        }

        /// 
        /// 清空当前DataBase中所有Key
        /// 
        public async Task KeyFulshAsync()
        {
            //直接执行清除命令
            await redis.ExecuteAsync("FLUSHDB");
        }

        /// 
        /// 判断key是否存在
        /// 
        /// 要判断的key
        /// 
        public async Task<bool> KeyExistsAsync(string key)
        {
            key = AddSysCustomKey(key);
            return await redis.KeyExistsAsync(key);
        }

        /// 
        /// 重新命名key
        /// 
        /// 就的redis key
        /// 新的redis key
        /// 
        public async Task<bool> KeyRenameAsync(string key, string newKey)
        {
            key = AddSysCustomKey(key);
            newKey = AddSysCustomKey(newKey);
            return await redis.KeyRenameAsync(key, newKey);
        }

        /// 
        /// 设置Key的过期时间
        /// 
        /// redis key
        /// 过期时间
        /// 
        public async Task<bool> KeyExpireAsync(string key, TimeSpan? expiry = default(TimeSpan?))
        {
            key = AddSysCustomKey(key);
            return await redis.KeyExpireAsync(key, expiry);
        }
        #endregion

        #endregion 

        #endregion

        #region 辅助方法

        /// 
        /// 将对象转换成string字符串
        /// 
        /// 
        /// 
        /// 
        protected string ConvertJson<T>(T value)
        {
            string result = value is string ? value.ToString() :
                JsonConvert.SerializeObject(value, Formatting.None);
            return result;
        }
        /// 
        /// 将值反系列化成对象
        /// 
        /// 
        /// 
        /// 
        protected T ConvertObj<T>(RedisValue value)
        {
            return value.IsNullOrEmpty ? default(T) : JsonConvert.DeserializeObject<T>(value);
        }

        /// 
        /// 将值反系列化成对象集合
        /// 
        /// 
        /// 
        /// 
        protected List<T> ConvetList<T>(RedisValue[] values)
        {
            List<T> result = new List<T>();
            foreach (var item in values)
            {
                var model = ConvertObj<T>(item);
                result.Add(model);
            }
            return result;
        }
        /// 
        /// 将string类型的Key转换成  型的Key
        /// 
        /// 
        /// 
        protected RedisKey[] ConvertRedisKeys(List<string> redisKeys) => redisKeys.Select(redisKey => (RedisKey)redisKey).ToArray();

        /// 
        /// 将string类型的Key转换成  型的Key
        /// 
        /// 
        /// 
        protected RedisKey[] ConvertRedisKeys(params string[] redisKeys) => redisKeys.Select(redisKey => (RedisKey)redisKey).ToArray();

        /// 
        /// 将string类型的Key转换成  型的Key,并添加前缀字符串
        /// 
        /// 
        /// 
        protected RedisKey[] ConvertRedisKeysAddSysCustomKey(params string[] redisKeys) => redisKeys.Select(redisKey => (RedisKey)AddSysCustomKey(redisKey)).ToArray();
        /// 
        /// 将值集合转换成RedisValue集合
        /// 
        /// 
        /// 
        /// 
        protected RedisValue[] ConvertRedisValue<T>(params T[] redisValues) => redisValues.Select(o => (RedisValue)ConvertJson<T>(o)).ToArray();
        #endregion 辅助方法

    }

服务层:五大数据结构

/// 
    /// Hash:类似dictionary,通过索引快速定位到指定元素的,耗时均等,跟string的区别在于不用反序列化,直接修改某个字段
    /// string的话要么是 001:序列化整个实体
    ///           要么是 001_name:  001_pwd: 多个key-value
    /// Hash的话,一个hashid-{key:value;key:value;key:value;}
    /// 可以一次性查找实体,也可以单个,还可以单个修改
    /// 
    public class RedisHashService : RedisBase
    {

        #region 构造函数

        /// 
        /// 初始化Redis的Hash数据结构操作
        /// 
        /// 操作的数据库索引0-64(需要在conf文件中配置)
        public RedisHashService(int? dbNum = null) :
            base(dbNum)
        { }
        #endregion

        #region 同步方法

        /// 
        /// 判断某个数据是否已经被缓存
        /// 
        /// 
        /// 
        /// 
        public bool HashExists(string key, string dataKey)
        {
            key = AddSysCustomKey(key);
            return base.redis.HashExists(key, dataKey);
        }

        /// 
        /// 存储数据到hash表
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public bool HashSet<T>(string key, string dataKey, T t)
        {
            key = AddSysCustomKey(key);
            string json = ConvertJson(t);
            return base.redis.HashSet(key, dataKey, json);
        }

        /// 
        /// 移除hash中的某值
        /// 
        /// 
        /// 
        /// 
        public bool HashDelete(string key, string dataKey)
        {
            key = AddSysCustomKey(key);
            return base.redis.HashDelete(key, dataKey);
        }

        /// 
        /// 移除hash中的多个值
        /// 
        /// 
        /// 
        /// 
        public long HashDelete(string key, params string[] dataKeys)
        {
            key = AddSysCustomKey(key);
            var newValues = dataKeys.Select(o => (RedisValue)o).ToArray();
            return base.redis.HashDelete(key, newValues);
        }

        /// 
        /// 从hash表获取数据
        /// 
        /// 
        /// 
        /// 
        /// 
        public T HashGet<T>(string key, string dataKey)
        {
            key = AddSysCustomKey(key);
            string value = base.redis.HashGet(key, dataKey);
            return ConvertObj<T>(value);
        }

        /// 
        /// 数字增长val,返回自增后的值
        /// 
        /// 
        /// 
        /// 可以为负
        /// 增长后的值
        public double HashIncrement(string key, string dataKey, double val = 1)
        {
            key = AddSysCustomKey(key);
            return base.redis.HashIncrement(key, dataKey, val);
        }

        /// 
        /// 数字减少val,返回自减少的值
        /// 
        /// 
        /// 
        /// 可以为负
        /// 减少后的值
        public double HashDecrement(string key, string dataKey, double val = 1)
        {
            key = AddSysCustomKey(key);
            return base.redis.HashDecrement(key, dataKey, val);
        }

        /// 
        /// 获取hashkey所有key名称
        /// 
        /// 
        /// 
        public string[] HashKeys(string key)
        {
            key = AddSysCustomKey(key);
            RedisValue[] values = base.redis.HashKeys(key);
            return values.Select(o=>o.ToString()).ToArray();
        }

        /// 
        /// 获取hashkey所有key与值,必须保证Key内的所有数据类型一致
        /// 
        /// 
        /// 
        /// 
        public Dictionary<string, T> HashGetAll<T>(string key)
        {
            key = AddSysCustomKey(key);
            var query = base.redis.HashGetAll(key);
            Dictionary<string, T> dic = new Dictionary<string, T>();
            foreach (var item in query)
            {
                dic.Add(item.Name, ConvertObj<T>(item.Value));
            }
            return dic;
        }

        #endregion 同步方法

        #region 异步方法

        /// 
        /// 异步方法 判断某个数据是否已经被缓存
        /// 
        /// 
        /// 
        /// 
        public async Task<bool> HashExistsAsync(string key, string dataKey)
        {
            key = AddSysCustomKey(key);
            return await base.redis.HashExistsAsync(key, dataKey);
        }

        /// 
        /// 异步方法 存储数据到hash表
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<bool> HashSetAsync<T>(string key, string dataKey, T t)
        {
            key = AddSysCustomKey(key);
            string json = ConvertJson(t);
            return await base.redis.HashSetAsync(key, dataKey, json);
        }

        /// 
        /// 异步方法 移除hash中的某值
        /// 
        /// 
        /// 
        /// 
        public async Task<bool> HashDeleteAsync(string key, string dataKey)
        {
            key = AddSysCustomKey(key);
            return await base.redis.HashDeleteAsync(key, dataKey);
        }

        /// 
        /// 异步方法 移除hash中的多个值
        /// 
        /// 
        /// 
        /// 
        public async Task<long> HashDeleteAsync(string key, params string[] dataKeys)
        {
            key = AddSysCustomKey(key);
            var newValues = dataKeys.Select(o => (RedisValue)o).ToArray();
            return await base.redis.HashDeleteAsync(key, newValues);
        }

        /// 
        /// 异步方法 从hash表获取数据
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<T> HashGetAsync<T>(string key, string dataKey)
        {
            key = AddSysCustomKey(key);
            string value = await base.redis.HashGetAsync(key, dataKey);
            return ConvertObj<T>(value);
        }

        /// 
        /// 异步方法 数字增长val,返回自增后的值
        /// 
        /// 
        /// 
        /// 可以为负
        /// 增长后的值
        public async Task<double> HashIncrementAsync(string key, string dataKey, double val = 1)
        {
            key = AddSysCustomKey(key);
            return await base.redis.HashIncrementAsync(key, dataKey, val);
        }

        /// 
        /// 异步方法 数字减少val,返回自减少的值
        /// 
        /// 
        /// 
        /// 可以为负
        /// 减少后的值
        public async Task<double> HashDecrementAsync(string key, string dataKey, double val = 1)
        {
            key = AddSysCustomKey(key);
            return await base.redis.HashDecrementAsync(key, dataKey, val);
        }

        /// 
        /// 异步方法 获取hashkey所有key名称
        /// 
        /// 
        /// 
        public async Task<string[]> HashKeysAsync(string key)
        {
            key = AddSysCustomKey(key);
            RedisValue[] values = await base.redis.HashKeysAsync(key);
            return values.Select(o => o.ToString()).ToArray();
        }

        /// 
        /// 获取hashkey所有key与值,必须保证Key内的所有数据类型一致
        /// 
        /// 
        /// 
        /// 
        public async Task<Dictionary<string, T>> HashGetAllAsync<T>(string key)
        {
            key = AddSysCustomKey(key);
            var query = await base.redis.HashGetAllAsync(key);
            Dictionary<string, T> dic = new Dictionary<string, T>();
            foreach (var item in query)
            {
                dic.Add(item.Name, ConvertObj<T>(item.Value));
            }
            return dic;
        }

        #endregion 异步方法

    }
/// 
    /// Redis list的实现为一个双向链表,即可以支持反向查找和遍历,更方便操作,不过带来了部分额外的内存开销,
    /// Redis内部的很多实现,包括发送缓冲队列等也都是用的这个数据结构。  
    /// 一般是左进右出或者右进左出 
    /// 
    public class RedisListService : RedisBase
    {
        #region 构造函数

        /// 
        /// 初始化Redis的List数据结构操作
        /// 
        /// 操作的数据库索引0-64(需要在conf文件中配置)
        public RedisListService(int? dbNum = null) :
            base(dbNum)
        { }
        #endregion

        #region 同步方法
        /// 
        /// 从左侧向list中添加一个值,返回集合总数
        /// 
        /// 
        /// 
        /// 
        /// 
        public long ListLeftPush<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return base.redis.ListLeftPush(key, jValue);
        }

        /// 
        /// 从左侧向list中添加多个值,返回集合总数
        /// 
        /// 
        /// 
        /// 
        /// 
        public long ListLeftPush<T>(string key, List<T> value)
        {
            key = AddSysCustomKey(key);
            RedisValue[] valueList = base.ConvertRedisValue(value.ToArray());
            return base.redis.ListLeftPush(key, valueList);
        }

        /// 
        /// 从右侧向list中添加一个值,返回集合总数
        /// 
        /// 
        /// 
        /// 
        /// 
        public long ListRightPush<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return base.redis.ListRightPush(key, jValue);
        }

        /// 
        /// 从右侧向list中添加多个值,返回集合总数
        /// 
        /// 
        /// 
        /// 
        /// 
        public long ListRightPush<T>(string key, List<T> value)
        {
            key = AddSysCustomKey(key);
            RedisValue[] valueList = base.ConvertRedisValue(value.ToArray());
            return base.redis.ListRightPush(key, valueList);
        }

        /// 
        /// 从左侧向list中取出一个值并从list中删除
        /// 
        /// 
        /// 
        /// 
        public T ListLeftPop<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = base.redis.ListLeftPop(key);
            return base.ConvertObj<T>(rValue);
        }

        /// 
        /// 从右侧向list中取出一个值并从list中删除
        /// 
        /// 
        /// 
        /// 
        public T ListRightPop<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = base.redis.ListRightPop(key);
            return base.ConvertObj<T>(rValue);
        }

        /// 
        /// 从key的List中右侧取出一个值,并从左侧添加到destination集合中,且返回该数据对象
        /// 
        /// 
        /// 要取出数据的List名称
        /// 要添加到的List名称
        /// 
        public T ListRightPopLeftPush<T>(string key, string destination)
        {
            key = AddSysCustomKey(key);
            destination = AddSysCustomKey(destination);
            var rValue = base.redis.ListRightPopLeftPush(key, destination);
            return base.ConvertObj<T>(rValue);
        }

        /// 
        /// 在key的List指定值pivot之后插入value,返回集合总数
        /// 
        /// 
        /// 
        /// 索引值
        /// 要插入的值
        /// 
        public long ListInsertAfter<T>(string key, T pivot, T value)
        {
            key = AddSysCustomKey(key);
            string pValue = ConvertJson(pivot);
            string jValue = ConvertJson(value);
            return base.redis.ListInsertAfter(key, pValue, jValue);
        }

        /// 
        /// 在key的List指定值pivot之前插入value,返回集合总数
        /// 
        /// 
        /// 
        /// 索引值
        /// 要插入的值
        /// 
        public long ListInsertBefore<T>(string key, T pivot, T value)
        {
            key = AddSysCustomKey(key);
            string pValue = ConvertJson(pivot);
            string jValue = ConvertJson(value);
            return base.redis.ListInsertBefore(key, pValue, jValue);
        }

        /// 
        /// 从key的list中取出所有数据
        /// 
        /// 
        /// 
        /// 
        public List<T> ListRange<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = base.redis.ListRange(key);
            return base.ConvetList<T>(rValue);
        }

        /// 
        /// 从key的List获取指定索引的值
        /// 
        /// 
        /// 
        /// 
        /// 
        public T ListGetByIndex<T>(string key, long index)
        {
            key = AddSysCustomKey(key);
            var rValue = base.redis.ListGetByIndex(key, index);
            return base.ConvertObj<T>(rValue);
        }

        /// 
        /// 获取key的list中数据个数
        /// 
        /// 
        /// 
        public long ListLength(string key)
        {
            key = AddSysCustomKey(key);
            return base.redis.ListLength(key);
        }

        /// 
        /// 从key的List中移除指定的值,返回删除个数
        /// 
        /// 
        /// 
        /// 
        /// 
        public long ListRemove<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return base.redis.ListRemove(key, jValue);
        }
        #endregion

        #region 异步方法
        /// 
        /// 从左侧向list中添加一个值,返回集合总数
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<long> ListLeftPushAsync<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return await base.redis.ListLeftPushAsync(key, jValue);
        }

        /// 
        /// 从左侧向list中添加多个值,返回集合总数
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<long> ListLeftPushAsync<T>(string key, List<T> value)
        {
            key = AddSysCustomKey(key);
            RedisValue[] valueList = base.ConvertRedisValue(value.ToArray());
            return await base.redis.ListLeftPushAsync(key, valueList);
        }

        /// 
        /// 从右侧向list中添加一个值,返回集合总数
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<long> ListRightPushAsync<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return await base.redis.ListRightPushAsync(key, jValue);
        }

        /// 
        /// 从右侧向list中添加多个值,返回集合总数
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<long> ListRightPushAsync<T>(string key, List<T> value)
        {
            key = AddSysCustomKey(key);
            RedisValue[] valueList = base.ConvertRedisValue(value.ToArray());
            return await base.redis.ListRightPushAsync(key, valueList);
        }

        /// 
        /// 从左侧向list中取出一个值并从list中删除
        /// 
        /// 
        /// 
        /// 
        public async Task<T> ListLeftPopAsync<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = await base.redis.ListLeftPopAsync(key);
            return base.ConvertObj<T>(rValue);
        }

        /// 
        /// 从右侧向list中取出一个值并从list中删除
        /// 
        /// 
        /// 
        /// 
        public async Task<T> ListRightPopAsync<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = await base.redis.ListRightPopAsync(key);
            return base.ConvertObj<T>(rValue);
        }

        /// 
        /// 从key的List中右侧取出一个值,并从左侧添加到destination集合中,且返回该数据对象
        /// 
        /// 
        /// 要取出数据的List名称
        /// 要添加到的List名称
        /// 
        public async Task<T> ListRightPopLeftPushAsync<T>(string key, string destination)
        {
            key = AddSysCustomKey(key);
            destination = AddSysCustomKey(destination);
            var rValue = await base.redis.ListRightPopLeftPushAsync(key, destination);
            return base.ConvertObj<T>(rValue);
        }

        /// 
        /// 在key的List指定值pivot之后插入value,返回集合总数
        /// 
        /// 
        /// 
        /// 索引值
        /// 要插入的值
        /// 
        public async Task<long> ListInsertAfterAsync<T>(string key, T pivot, T value)
        {
            key = AddSysCustomKey(key);
            string pValue = ConvertJson(pivot);
            string jValue = ConvertJson(value);
            return await  base.redis.ListInsertAfterAsync(key, pValue, jValue);
        }

        /// 
        /// 在key的List指定值pivot之前插入value,返回集合总数
        /// 
        /// 
        /// 
        /// 索引值
        /// 要插入的值
        /// 
        public async Task<long> ListInsertBeforeAsync<T>(string key, T pivot, T value)
        {
            key = AddSysCustomKey(key);
            string pValue = ConvertJson(pivot);
            string jValue = ConvertJson(value);
            return await  base.redis.ListInsertBeforeAsync(key, pValue, jValue);
        }

        /// 
        /// 从key的list中取出所有数据
        /// 
        /// 
        /// 
        /// 
        public async Task<List<T>> ListRangeAsync<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = await base.redis.ListRangeAsync(key);
            return base.ConvetList<T>(rValue);
        }

        /// 
        /// 从key的List获取指定索引的值
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<T> ListGetByIndexAsync<T>(string key, long index)
        {
            key = AddSysCustomKey(key);
            var rValue = await base.redis.ListGetByIndexAsync(key, index);
            return base.ConvertObj<T>(rValue);
        }

        /// 
        /// 获取key的list中数据个数
        /// 
        /// 
        /// 
        public async Task<long> ListLengthAsync(string key)
        {
            key = AddSysCustomKey(key);
            return await base.redis.ListLengthAsync(key);
        }

        /// 
        /// 从key的List中移除指定的值,返回删除个数
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<long> ListRemoveAsync<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return await base.redis.ListRemoveAsync(key, jValue);
        }
        #endregion
    }
/// 
    /// Set:用哈希表来保持字符串的唯一性,没有先后顺序,存储一些集合性的数据
    /// 1.共同好友、二度好友
    /// 2.利用唯一性,可以统计访问网站的所有独立 IP
    /// 
    public class RedisSetService : RedisBase
    {
        #region 构造函数

        /// 
        /// 初始化Redis的Set无序数据结构操作
        /// 
        /// 操作的数据库索引0-64(需要在conf文件中配置)
        public RedisSetService(int? dbNum = null) :
            base(dbNum)
        { }
        #endregion

        #region 同步方法
        /// 
        /// 在Key集合中添加一个value值
        /// 
        /// 数据类型
        /// Key名称
        /// 
        /// 
        public bool SetAdd<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return base.redis.SetAdd(key, jValue);
        }
        /// 
        /// 在Key集合中添加多个value值
        /// 
        /// 数据类型
        /// Key名称
        /// 值列表
        /// 
        public long SetAdd<T>(string key, List<T> value)
        {
            key = AddSysCustomKey(key);
            RedisValue[] valueList = base.ConvertRedisValue(value.ToArray());
            return base.redis.SetAdd(key, valueList);
        }

        /// 
        /// 获取key集合值的数量
        /// 
        /// 
        /// 
        public long SetLength(string key)
        {
            key = AddSysCustomKey(key);
            return base.redis.SetLength(key);
        }

        /// 
        /// 判断Key集合中是否包含指定的值
        /// 
        /// 值类型
        /// 
        /// 要判断是值
        /// 
        public bool SetContains<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return base.redis.SetContains(key, jValue);
        }

        /// 
        /// 随机获取key集合中的一个值
        /// 
        /// 数据类型
        /// 
        /// 
        public T SetRandomMember<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = base.redis.SetRandomMember(key);
            return ConvertObj<T>(rValue);
        }

        /// 
        /// 获取key所有值的集合
        /// 
        /// 
        /// 
        /// 
        public List<T> SetMembers<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = base.redis.SetMembers(key);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 删除key集合中指定的value
        /// 
        /// 
        /// 
        /// 
        /// 
        public long SetRemove<T>(string key, params T[] value)
        {
            key = AddSysCustomKey(key);
            RedisValue[] valueList = base.ConvertRedisValue(value);
            return base.redis.SetRemove(key, valueList);
        }

        /// 
        /// 随机删除key集合中的一个值,并返回该值
        /// 
        /// 
        /// 
        /// 
        public T SetPop<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = base.redis.SetPop(key);
            return ConvertObj<T>(rValue);
        }


        /// 
        /// 获取几个集合的并集
        /// 
        /// 
        /// 要操作的Key集合
        /// 
        public List<T> SetCombineUnion<T>(params string[] keys)
        {
            return _SetCombine<T>(SetOperation.Union, keys);
        }
        /// 
        /// 获取几个集合的交集
        /// 
        /// 
        /// 要操作的Key集合
        /// 
        public List<T> SetCombineIntersect<T>(params string[] keys)
        {
            return _SetCombine<T>(SetOperation.Intersect, keys);
        }
        /// 
        /// 获取几个集合的差集
        /// 
        /// 
        /// 要操作的Key集合
        /// 
        public List<T> SetCombineDifference<T>(params string[] keys)
        {
            return _SetCombine<T>(SetOperation.Difference, keys);
        }

        /// 
        /// 获取几个集合的并集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public long SetCombineUnionAndStore(string destination, params string[] keys)
        {
            return _SetCombineAndStore(SetOperation.Union, destination, keys);
        }
        /// 
        /// 获取几个集合的交集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public long SetCombineIntersectAndStore(string destination, params string[] keys)
        {
            return _SetCombineAndStore(SetOperation.Intersect, destination, keys);
        }
        /// 
        /// 获取几个集合的差集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public long SetCombineDifferenceAndStore(string destination, params string[] keys)
        {
            return _SetCombineAndStore(SetOperation.Difference, destination, keys);
        }
        #endregion

        #region 异步方法
        /// 
        /// 在Key集合中添加一个value值
        /// 
        /// 数据类型
        /// Key名称
        /// 
        /// 
        public async Task<bool> SetAddAsync<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return await base.redis.SetAddAsync(key, jValue);
        }
        /// 
        /// 在Key集合中添加多个value值
        /// 
        /// 数据类型
        /// Key名称
        /// 值列表
        /// 
        public async Task<long> SetAddAsync<T>(string key, List<T> value)
        {
            key = AddSysCustomKey(key);
            RedisValue[] valueList = base.ConvertRedisValue(value.ToArray());
            return await base.redis.SetAddAsync(key, valueList);
        }

        /// 
        /// 获取key集合值的数量
        /// 
        /// 
        /// 
        public async Task<long> SetLengthAsync(string key)
        {
            key = AddSysCustomKey(key);
            return await base.redis.SetLengthAsync(key);
        }

        /// 
        /// 判断Key集合中是否包含指定的值
        /// 
        /// 值类型
        /// 
        /// 要判断是值
        /// 
        public async Task<bool> SetContainsAsync<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jValue = ConvertJson(value);
            return await base.redis.SetContainsAsync(key, jValue);
        }

        /// 
        /// 随机获取key集合中的一个值
        /// 
        /// 数据类型
        /// 
        /// 
        public async Task<T> SetRandomMemberAsync<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = await base.redis.SetRandomMemberAsync(key);
            return ConvertObj<T>(rValue);
        }

        /// 
        /// 获取key所有值的集合
        /// 
        /// 
        /// 
        /// 
        public async Task<List<T>> SetMembersAsync<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = await base.redis.SetMembersAsync(key);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 删除key集合中指定的value
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<long> SetRemoveAsync<T>(string key, params T[] value)
        {
            key = AddSysCustomKey(key);
            RedisValue[] valueList = base.ConvertRedisValue(value);
            return await base.redis.SetRemoveAsync(key, valueList);
        }

        /// 
        /// 随机删除key集合中的一个值,并返回该值
        /// 
        /// 
        /// 
        /// 
        public async Task<T> SetPopAsync<T>(string key)
        {
            key = AddSysCustomKey(key);
            var rValue = await base.redis.SetPopAsync(key);
            return ConvertObj<T>(rValue);
        }


        /// 
        /// 获取几个集合的并集
        /// 
        /// 
        /// 要操作的Key集合
        /// 
        public async Task<List<T>> SetCombineUnionAsync<T>(params string[] keys)
        {
            return await _SetCombineAsync<T>(SetOperation.Union, keys);
        }
        /// 
        /// 获取几个集合的交集
        /// 
        /// 
        /// 要操作的Key集合
        /// 
        public async Task<List<T>> SetCombineIntersectAsync<T>(params string[] keys)
        {
            return await _SetCombineAsync<T>(SetOperation.Intersect, keys);
        }
        /// 
        /// 获取几个集合的差集
        /// 
        /// 
        /// 要操作的Key集合
        /// 
        public async Task<List<T>> SetCombineDifferenceAsync<T>(params string[] keys)
        {
            return await _SetCombineAsync<T>(SetOperation.Difference, keys);
        }



        /// 
        /// 获取几个集合的并集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public async Task<long> SetCombineUnionAndStoreAsync(string destination, params string[] keys)
        {
            return await _SetCombineAndStoreAsync(SetOperation.Union, destination, keys);
        }
        /// 
        /// 获取几个集合的交集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public async Task<long> SetCombineIntersectAndStoreAsync(string destination, params string[] keys)
        {
            return await _SetCombineAndStoreAsync(SetOperation.Intersect, destination, keys);
        }
        /// 
        /// 获取几个集合的差集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public async Task<long> SetCombineDifferenceAndStoreAsync(string destination, params string[] keys)
        {
            return await _SetCombineAndStoreAsync(SetOperation.Difference, destination, keys);
        }

        #endregion

        #region 内部辅助方法
        /// 
        /// 获取几个集合的交叉并集合
        /// 
        /// 
        /// Union:并集  Intersect:交集  Difference:差集  详见 
        /// 要操作的Key集合
        /// 
        private List<T> _SetCombine<T>(SetOperation operation, params string[] keys)
        {
            RedisKey[] keyList = base.ConvertRedisKeysAddSysCustomKey(keys);
            var rValue = base.redis.SetCombine(operation, keyList);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 获取几个集合的交叉并集合,并保存到一个新Key中
        /// 
        /// Union:并集  Intersect:交集  Difference:差集  详见 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        private long _SetCombineAndStore(SetOperation operation, string destination, params string[] keys)
        {
            destination = AddSysCustomKey(destination);
            RedisKey[] keyList = base.ConvertRedisKeysAddSysCustomKey(keys);
            return base.redis.SetCombineAndStore(operation, destination, keyList);
        }
        /// 
        /// 获取几个集合的交叉并集合
        /// 
        /// 
        /// Union:并集  Intersect:交集  Difference:差集  详见 
        /// 要操作的Key集合
        /// 
        private async Task<List<T>> _SetCombineAsync<T>(SetOperation operation, params string[] keys)
        {
            RedisKey[] keyList = base.ConvertRedisKeysAddSysCustomKey(keys);
            var rValue = await base.redis.SetCombineAsync(operation, keyList);
            return ConvetList<T>(rValue);
        }
        /// 
        /// 获取几个集合的交叉并集合,并保存到一个新Key中
        /// 
        /// Union:并集  Intersect:交集  Difference:差集  详见 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        private async Task<long> _SetCombineAndStoreAsync(SetOperation operation, string destination, params string[] keys)
        {
            destination = AddSysCustomKey(destination);
            RedisKey[] keyList = base.ConvertRedisKeysAddSysCustomKey(keys);
            return await base.redis.SetCombineAndStoreAsync(operation, destination, keyList);
        }

        #endregion

    }
/// 
    /// Sorted Sets是将 Set 中的元素增加了一个权重参数 score,使得集合中的元素能够按 score 进行有序排列
    /// 1.带有权重的元素,比如一个游戏的用户得分排行榜
    /// 2.比较复杂的数据结构,一般用到的场景不算太多
    /// 
    public class RedisSortedSetService : RedisBase
    {
        #region 构造函数

        /// 
        /// 初始化Redis的SortedSet有序数据结构操作
        /// 
        /// 操作的数据库索引0-64(需要在conf文件中配置)
        public RedisSortedSetService(int? dbNum = null) :
            base(dbNum)
        { }
        #endregion

        #region 同步方法

        /// 
        /// 添加一个值到Key
        /// 
        /// 
        /// 
        /// 
        /// 排序分数,为空将获取集合中最大score加1
        /// 
        public bool SortedSetAdd<T>(string key, T value, double? score = null)
        {
            key = AddSysCustomKey(key);
            double scoreNum = score ?? _GetScore(key);
            return base.redis.SortedSetAdd(key, ConvertJson<T>(value), scoreNum);
        }

        /// 
        /// 添加一个集合到Key
        /// 
        /// 
        /// 
        /// 
        /// 排序分数,为空将获取集合中最大score加1
        /// 
        public long SortedSetAdd<T>(string key, List<T> value, double? score = null)
        {
            key = AddSysCustomKey(key);
            double scoreNum = score ?? _GetScore(key);
            SortedSetEntry[] rValue = value.Select(o => new SortedSetEntry(ConvertJson<T>(o), scoreNum++)).ToArray();
            return base.redis.SortedSetAdd(key, rValue);
        }

        /// 
        /// 获取集合中的数量
        /// 
        /// 
        /// 
        public long SortedSetLength(string key)
        {
            key = AddSysCustomKey(key);
            return redis.SortedSetLength(key);
        }

        /// 
        /// 获取指定起始值到结束值的集合数量
        /// 
        /// 
        /// 
        /// 起始值
        /// 结束值
        /// 
        public long SortedSetLengthByValue<T>(string key, T startValue, T endValue)
        {
            key = AddSysCustomKey(key);
            var sValue = ConvertJson<T>(startValue);
            var eValue = ConvertJson<T>(endValue);
            return redis.SortedSetLengthByValue(key, sValue, eValue);
        }

        /// 
        /// 获取指定Key的排序Score值
        /// 
        /// 
        /// 
        /// 
        /// 
        public double? SortedSetScore<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            var rValue = ConvertJson<T>(value);
            return redis.SortedSetScore(key, rValue);
        }

        /// 
        /// 获取指定Key中最小Score值
        /// 
        /// 
        /// 
        public double SortedSetMinScore(string key)
        {
            key = AddSysCustomKey(key);
            double dValue = 0;
            var rValue = base.redis.SortedSetRangeByRankWithScores(key, 0, 0, Order.Ascending).FirstOrDefault();
            dValue = rValue != null ? rValue.Score : 0;
            return dValue;
        }

        /// 
        /// 获取指定Key中最大Score值
        /// 
        /// 
        /// 
        public double SortedSetMaxScore(string key)
        {
            key = AddSysCustomKey(key);
            double dValue = 0;
            var rValue = base.redis.SortedSetRangeByRankWithScores(key, 0, 0, Order.Descending).FirstOrDefault();
            dValue = rValue != null ? rValue.Score : 0;
            return dValue;
        }

        /// 
        /// 删除Key中指定的值
        /// 
        /// 
        /// 
        public long SortedSetRemove<T>(string key, params T[] value)
        {
            key = AddSysCustomKey(key);
            var rValue = ConvertRedisValue<T>(value);
            return base.redis.SortedSetRemove(key, rValue);
        }

        /// 
        /// 删除指定起始值到结束值的数据
        /// 
        /// 
        /// 
        /// 起始值
        /// 结束值
        /// 
        public long SortedSetRemoveRangeByValue<T>(string key, T startValue, T endValue)
        {
            key = AddSysCustomKey(key);
            var sValue = ConvertJson<T>(startValue);
            var eValue = ConvertJson<T>(endValue);
            return base.redis.SortedSetRemoveRangeByValue(key, sValue, eValue);
        }

        /// 
        /// 删除 从 start 开始的 stop 条数据
        /// 
        /// 
        /// 
        /// 
        /// 
        public long SortedSetRemoveRangeByRank(string key, long start, long stop)
        {
            key = AddSysCustomKey(key);
            return base.redis.SortedSetRemoveRangeByRank(key, start, stop);
        }

        /// 
        /// 根据排序分数Score,删除从 start 开始的 stop 条数据
        /// 
        /// 
        /// 
        /// 
        /// 
        public long SortedSetRemoveRangeByScore(string key, double start, double stop)
        {
            key = AddSysCustomKey(key);
            return base.redis.SortedSetRemoveRangeByScore(key, start, stop);
        }

        /// 
        /// 获取从 start 开始的 stop 条数据
        /// 
        /// 
        /// 
        /// 起始数
        /// -1表示到结束,0为1条
        /// 是否按降序排列
        /// 
        public List<T> SortedSetRangeByRank<T>(string key, long start = 0, long stop = -1, bool desc = false)
        {
            key = AddSysCustomKey(key);
            Order orderBy = desc ? Order.Descending : Order.Ascending;
            var rValue = base.redis.SortedSetRangeByRank(key, start, stop, orderBy);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 获取从 start 开始的 stop 条数据包含Score,返回数据格式:Key=值,Value = Score
        /// 
        /// 
        /// 
        /// 起始数
        /// -1表示到结束,0为1条
        /// 是否按降序排列
        /// 
        public Dictionary<T, double> SortedSetRangeByRankWithScores<T>(string key, long start = 0, long stop = -1, bool desc = false)
        {
            key = AddSysCustomKey(key);
            Order orderBy = desc ? Order.Descending : Order.Ascending;
            var rValue = base.redis.SortedSetRangeByRankWithScores(key, start, stop, orderBy);
            Dictionary<T, double> dicList = new Dictionary<T, double>();
            foreach (var item in rValue)
            {
                dicList.Add(ConvertObj<T>(item.Element), item.Score);
            }
            return dicList;
        }

        /// 
        ///  根据Score排序 获取从 start 开始的 stop 条数据
        /// 
        /// 
        /// 
        /// 起始数
        /// -1表示到结束,0为1条
        /// 是否按降序排列
        /// 
        public List<T> SortedSetRangeByScore<T>(string key, double start = 0, double stop = -1, bool desc = false)
        {
            key = AddSysCustomKey(key);
            Order orderBy = desc ? Order.Descending : Order.Ascending;
            var rValue = base.redis.SortedSetRangeByScore(key, start, stop, Exclude.None, orderBy);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 根据Score排序  获取从 start 开始的 stop 条数据包含Score,返回数据格式:Key=值,Value = Score
        /// 
        /// 
        /// 
        /// 起始数
        /// -1表示到结束,0为1条
        /// 是否按降序排列
        /// 
        public Dictionary<T, double> SortedSetRangeByScoreWithScores<T>(string key, double start = 0, double stop = -1, bool desc = false)
        {
            key = AddSysCustomKey(key);
            Order orderBy = desc ? Order.Descending : Order.Ascending;
            var rValue = base.redis.SortedSetRangeByScoreWithScores(key, start, stop, Exclude.None, orderBy);
            Dictionary<T, double> dicList = new Dictionary<T, double>();
            foreach (var item in rValue)
            {
                dicList.Add(ConvertObj<T>(item.Element), item.Score);
            }
            return dicList;
        }

        /// 
        /// 获取指定起始值到结束值的数据
        /// 
        /// 
        /// 
        /// 起始值
        /// 结束值
        /// 
        public List<T> SortedSetRangeByValue<T>(string key, T startValue, T endValue)
        {
            key = AddSysCustomKey(key);
            var sValue = ConvertJson<T>(startValue);
            var eValue = ConvertJson<T>(endValue);
            var rValue = base.redis.SortedSetRangeByValue(key, sValue, eValue);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 获取几个集合的并集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public long SortedSetCombineUnionAndStore(string destination, params string[] keys)
        {
            return _SortedSetCombineAndStore(SetOperation.Union, destination, keys);
        }

        /// 
        /// 获取几个集合的交集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public long SortedSetCombineIntersectAndStore(string destination, params string[] keys)
        {
            return _SortedSetCombineAndStore(SetOperation.Intersect, destination, keys);
        }


        //交集似乎并不支持
        / 
        / 获取几个集合的差集,并保存到一个新Key中
        / 
        / 保存的新Key名称
        / 要操作的Key集合
        / 
        //public long SortedSetCombineDifferenceAndStore(string destination, params string[] keys)
        //{
        //    return _SortedSetCombineAndStore(SetOperation.Difference, destination, keys);
        //}



        /// 
        /// 修改指定Key和值的Scores在原值上减去scores,并返回最终Scores
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public double SortedSetDecrement<T>(string key, T value, double scores)
        {
            key = AddSysCustomKey(key);
            var rValue = ConvertJson<T>(value);
            return redis.SortedSetDecrement(key, rValue, scores);
        }

        /// 
        /// 修改指定Key和值的Scores在原值上增加scores,并返回最终Scores
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public double SortedSetIncrement<T>(string key, T value, double scores)
        {
            key = AddSysCustomKey(key);
            var rValue = ConvertJson<T>(value);
            return redis.SortedSetIncrement(key, rValue, scores);
        }



        #endregion

        #region 异步方法

        /// 
        /// 添加一个值到Key
        /// 
        /// 
        /// 
        /// 
        /// 排序分数,为空将获取集合中最大score加1
        /// 
        public async Task<bool> SortedSetAddAsync<T>(string key, T value, double? score = null)
        {
            key = AddSysCustomKey(key);
            double scoreNum = score ?? _GetScore(key);
            return await base.redis.SortedSetAddAsync(key, ConvertJson<T>(value), scoreNum);
        }

        /// 
        /// 添加一个集合到Key
        /// 
        /// 
        /// 
        /// 
        /// 排序分数,为空将获取集合中最大score加1
        /// 
        public async Task<long> SortedSetAddAsync<T>(string key, List<T> value, double? score = null)
        {
            key = AddSysCustomKey(key);
            double scoreNum = score ?? _GetScore(key);
            SortedSetEntry[] rValue = value.Select(o => new SortedSetEntry(ConvertJson<T>(o), scoreNum++)).ToArray();
            return await base.redis.SortedSetAddAsync(key, rValue);
        }

        /// 
        /// 获取集合中的数量
        /// 
        /// 
        /// 
        public async Task<long> SortedSetLengthAsync(string key)
        {
            key = AddSysCustomKey(key);
            return await redis.SortedSetLengthAsync(key);
        }

        /// 
        /// 获取指定起始值到结束值的集合数量
        /// 
        /// 
        /// 
        /// 起始值
        /// 结束值
        /// 
        public async Task<long> SortedSetLengthByValueAsync<T>(string key, T startValue, T endValue)
        {
            key = AddSysCustomKey(key);
            var sValue = ConvertJson<T>(startValue);
            var eValue = ConvertJson<T>(endValue);
            return await redis.SortedSetLengthByValueAsync(key, sValue, eValue);
        }

        /// 
        /// 获取指定Key的排序Score值
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<double?> SortedSetScoreAsync<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            var rValue = ConvertJson<T>(value);
            return await redis.SortedSetScoreAsync(key, rValue);
        }

        /// 
        /// 获取指定Key中最小Score值
        /// 
        /// 
        /// 
        public async Task<double> SortedSetMinScoreAsync(string key)
        {
            key = AddSysCustomKey(key);
            double dValue = 0;
            var rValue = (await base.redis.SortedSetRangeByRankWithScoresAsync(key, 0, 0, Order.Ascending)).FirstOrDefault();
            dValue = rValue != null ? rValue.Score : 0;
            return dValue;
        }

        /// 
        /// 获取指定Key中最大Score值
        /// 
        /// 
        /// 
        public async Task<double> SortedSetMaxScoreAsync(string key)
        {
            key = AddSysCustomKey(key);
            double dValue = 0;
            var rValue = (await base.redis.SortedSetRangeByRankWithScoresAsync(key, 0, 0, Order.Descending)).FirstOrDefault();
            dValue = rValue != null ? rValue.Score : 0;
            return dValue;
        }

        /// 
        /// 删除Key中指定的值
        /// 
        /// 
        /// 
        public async Task<long> SortedSetRemoveAsync<T>(string key, params T[] value)
        {
            key = AddSysCustomKey(key);
            var rValue = ConvertRedisValue<T>(value);
            return await base.redis.SortedSetRemoveAsync(key, rValue);
        }

        /// 
        /// 删除指定起始值到结束值的数据
        /// 
        /// 
        /// 
        /// 起始值
        /// 结束值
        /// 
        public async Task<long> SortedSetRemoveRangeByValueAsync<T>(string key, T startValue, T endValue)
        {
            key = AddSysCustomKey(key);
            var sValue = ConvertJson<T>(startValue);
            var eValue = ConvertJson<T>(endValue);
            return await base.redis.SortedSetRemoveRangeByValueAsync(key, sValue, eValue);
        }

        /// 
        /// 删除 从 start 开始的 stop 条数据
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<long> SortedSetRemoveRangeByRankAsync(string key, long start, long stop)
        {
            key = AddSysCustomKey(key);
            return await base.redis.SortedSetRemoveRangeByRankAsync(key, start, stop);
        }

        /// 
        /// 根据排序分数Score,删除从 start 开始的 stop 条数据
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<long> SortedSetRemoveRangeByScoreAsync(string key, double start, double stop)
        {
            key = AddSysCustomKey(key);
            return await base.redis.SortedSetRemoveRangeByScoreAsync(key, start, stop);
        }

        /// 
        /// 获取从 start 开始的 stop 条数据
        /// 
        /// 
        /// 
        /// 起始数
        /// -1表示到结束,0为1条
        /// 是否按降序排列
        /// 
        public async Task<List<T>> SortedSetRangeByRankAsync<T>(string key, long start = 0, long stop = -1, bool desc = false)
        {
            key = AddSysCustomKey(key);
            Order orderBy = desc ? Order.Descending : Order.Ascending;
            var rValue = await base.redis.SortedSetRangeByRankAsync(key, start, stop, orderBy);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 获取从 start 开始的 stop 条数据包含Score,返回数据格式:Key=值,Value = Score
        /// 
        /// 
        /// 
        /// 起始数
        /// -1表示到结束,0为1条
        /// 是否按降序排列
        /// 
        public async Task<Dictionary<T, double>> SortedSetRangeByRankWithScoresAsync<T>(string key, long start = 0, long stop = -1, bool desc = false)
        {
            key = AddSysCustomKey(key);
            Order orderBy = desc ? Order.Descending : Order.Ascending;
            var rValue = await base.redis.SortedSetRangeByRankWithScoresAsync(key, start, stop, orderBy);
            Dictionary<T, double> dicList = new Dictionary<T, double>();
            foreach (var item in rValue)
            {
                dicList.Add(ConvertObj<T>(item.Element), item.Score);
            }
            return dicList;
        }

        /// 
        ///  根据Score排序 获取从 start 开始的 stop 条数据
        /// 
        /// 
        /// 
        /// 起始数
        /// -1表示到结束,0为1条
        /// 是否按降序排列
        /// 
        public async Task<List<T>> SortedSetRangeByScoreAsync<T>(string key, double start = 0, double stop = -1, bool desc = false)
        {
            key = AddSysCustomKey(key);
            Order orderBy = desc ? Order.Descending : Order.Ascending;
            var rValue = await base.redis.SortedSetRangeByScoreAsync(key, start, stop, Exclude.None, orderBy);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 根据Score排序  获取从 start 开始的 stop 条数据包含Score,返回数据格式:Key=值,Value = Score
        /// 
        /// 
        /// 
        /// 起始数
        /// -1表示到结束,0为1条
        /// 是否按降序排列
        /// 
        public async Task<Dictionary<T, double>> SortedSetRangeByScoreWithScoresAsync<T>(string key, double start = 0, double stop = -1, bool desc = false)
        {
            key = AddSysCustomKey(key);
            Order orderBy = desc ? Order.Descending : Order.Ascending;
            var rValue = await base.redis.SortedSetRangeByScoreWithScoresAsync(key, start, stop, Exclude.None, orderBy);
            Dictionary<T, double> dicList = new Dictionary<T, double>();
            foreach (var item in rValue)
            {
                dicList.Add(ConvertObj<T>(item.Element), item.Score);
            }
            return dicList;
        }

        /// 
        /// 获取指定起始值到结束值的数据
        /// 
        /// 
        /// 
        /// 起始值
        /// 结束值
        /// 
        public async Task<List<T>> SortedSetRangeByValueAsync<T>(string key, T startValue, T endValue)
        {
            key = AddSysCustomKey(key);
            var sValue = ConvertJson<T>(startValue);
            var eValue = ConvertJson<T>(endValue);
            var rValue = await base.redis.SortedSetRangeByValueAsync(key, sValue, eValue);
            return ConvetList<T>(rValue);
        }

        /// 
        /// 获取几个集合的并集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public async Task<long> SortedSetCombineUnionAndStoreAsync(string destination, params string[] keys)
        {
            return await _SortedSetCombineAndStoreAsync(SetOperation.Union, destination, keys);
        }

        /// 
        /// 获取几个集合的交集,并保存到一个新Key中
        /// 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        public async Task<long> SortedSetCombineIntersectAndStoreAsync(string destination, params string[] keys)
        {
            return await _SortedSetCombineAndStoreAsync(SetOperation.Intersect, destination, keys);
        }

        / 
        / 获取几个集合的差集,并保存到一个新Key中
        / 
        / 保存的新Key名称
        / 要操作的Key集合
        / 
        //public async Task SortedSetCombineDifferenceAndStoreAsync(string destination, params string[] keys)
        //{
        //    return await _SortedSetCombineAndStoreAsync(SetOperation.Difference, destination, keys);
        //}

        /// 
        /// 修改指定Key和值的Scores在原值上减去scores,并返回最终Scores
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<double> SortedSetDecrementAsync<T>(string key, T value, double scores)
        {
            key = AddSysCustomKey(key);
            var rValue = ConvertJson<T>(value);
            return await base.redis.SortedSetDecrementAsync(key, rValue, scores);
        }

        /// 
        /// 修改指定Key和值的Scores在原值上增加scores,并返回最终Scores
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public async Task<double> SortedSetIncrementAsync<T>(string key, T value, double scores)
        {
            key = AddSysCustomKey(key);
            var rValue = ConvertJson<T>(value);
            return await base.redis.SortedSetIncrementAsync(key, rValue, scores);
        }



        #endregion

        #region 内部辅助方法
        /// 
        /// 获取指定Key中最大Score值,
        /// 
        /// key名称,注意要先添加上Key前缀
        /// 
        private double _GetScore(string key)
        {
            double dValue = 0;
            var rValue = base.redis.SortedSetRangeByRankWithScores(key, 0, 0, Order.Descending).FirstOrDefault();
            dValue = rValue != null ? rValue.Score : 0;
            return dValue + 1;
        }

        /// 
        /// 获取几个集合的交叉并集合,并保存到一个新Key中
        /// 
        /// Union:并集  Intersect:交集  Difference:差集  详见 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        private long _SortedSetCombineAndStore(SetOperation operation, string destination, params string[] keys)
        {
            #region 查看源码,似乎并不支持Difference
            //RedisCommand command;
            //if (operation != SetOperation.Union)
            //{
            //    if (operation != SetOperation.Intersect)
            //    {
            //        throw new ArgumentOutOfRangeException("operation");
            //    }
            //    command = RedisCommand.ZINTERSTORE;
            //}
            //else
            //{
            //    command = RedisCommand.ZUNIONSTORE;
            //}
            #endregion

            destination = AddSysCustomKey(destination);
            RedisKey[] keyList = base.ConvertRedisKeysAddSysCustomKey(keys);
            var rValue = base.redis.SortedSetCombineAndStore(operation, destination, keyList);
            return rValue;

        }

        /// 
        /// 获取几个集合的交叉并集合,并保存到一个新Key中
        /// 
        /// Union:并集  Intersect:交集  Difference:差集  详见 
        /// 保存的新Key名称
        /// 要操作的Key集合
        /// 
        private async Task<long> _SortedSetCombineAndStoreAsync(SetOperation operation, string destination, params string[] keys)
        {
            destination = AddSysCustomKey(destination);
            RedisKey[] keyList = base.ConvertRedisKeysAddSysCustomKey(keys);
            var rValue = await base.redis.SortedSetCombineAndStoreAsync(operation, destination, keyList);
            return rValue;
        }

        #endregion
    }
/// 
    /// key-value 键值对:value可以是序列化的数据
    /// 
    public class RedisStringService : RedisBase
    {
        #region 构造函数

        /// 
        /// 初始化Redis的String数据结构操作
        /// 
        /// 操作的数据库索引0-64(需要在conf文件中配置)
        public RedisStringService(int? dbNum = null) :
            base(dbNum)
        { }
        #endregion

        #region 同步方法
        /// 
        /// 添加单个key value
        /// 
        /// Redis Key
        /// 保存的值
        /// 过期时间
        /// 
        public bool StringSet(string key, string value, TimeSpan? expiry = default(TimeSpan?))
        {
            key = AddSysCustomKey(key);
            return base.redis.StringSet(key, value, expiry);
        }

        /// 
        /// 添加多个key/value
        /// 
        /// key/value集合
        /// 
        public bool StringSet(Dictionary<string, string> valueList)
        {
            var newkeyValues = valueList.Select(p => new KeyValuePair<RedisKey, RedisValue>(AddSysCustomKey(p.Key), p.Value)).ToArray();
            return base.redis.StringSet(newkeyValues);
        }

        /// 
        /// 保存一个对象
        /// 
        /// 对象类型
        /// 保存的Key名称
        /// 对象实体
        /// 过期时间
        /// 
        public bool StringSet<T>(string key, T value, TimeSpan? expiry = default(TimeSpan?))
        {
            key = AddSysCustomKey(key);
            string jsonValue = ConvertJson(value);
            return base.redis.StringSet(key, jsonValue, expiry);
        }

        /// 
        /// 在原有key的value值之后追加value
        /// 
        /// 追加的Key名称
        /// 追加的值
        /// 
        public long StringAppend(string key, string value)
        {
            key = AddSysCustomKey(key);
            return base.redis.StringAppend(key, value);
        }

        /// 
        /// 获取单个key的值
        /// 
        /// 要读取的Key名称
        /// 
        public string StringGet(string key)
        {
            key = AddSysCustomKey(key);
            return base.redis.StringGet(key);
        }

        /// 
        /// 获取多个key的value值
        /// 
        /// 要获取值的Key集合
        /// 
        public List<string> StringGet(params string[] keys)
        {
            var newKeys = ConvertRedisKeysAddSysCustomKey(keys);
            var values = base.redis.StringGet(newKeys);
            return values.Select(o => o.ToString()).ToList();
        }


        /// 
        /// 获取单个key的value值
        /// 
        /// 返回数据类型
        /// 要获取值的Key集合
        /// 
        public T StringGet<T>(string key)
        {
            key = AddSysCustomKey(key);
            var values = base.redis.StringGet(key);
            return ConvertObj<T>(values);
        }

        /// 
        /// 获取多个key的value值
        /// 
        /// 返回数据类型
        /// 要获取值的Key集合
        /// 
        public List<T> StringGet<T>(params string[] keys)
        {
            var newKeys = ConvertRedisKeysAddSysCustomKey(keys);
            var values = base.redis.StringGet(newKeys);
            return ConvetList<T>(values);
        }

        /// 
        /// 获取旧值赋上新值
        /// 
        /// Key名称
        /// 新值
        /// 
        public string StringGetSet(string key, string value)
        {
            key = AddSysCustomKey(key);
            return base.redis.StringGetSet(key, value);
        }

        /// 
        /// 获取旧值赋上新值
        /// 
        /// 数据类型
        /// Key名称
        /// 新值
        /// 
        public T StringGetSet<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jsonValue = ConvertJson(value);
            var oValue = base.redis.StringGetSet(key, jsonValue);
            return ConvertObj<T>(oValue);
        }


        /// 
        /// 获取值的长度
        /// 
        /// Key名称
        /// 
        public long StringGetLength(string key)
        {
            key = AddSysCustomKey(key);
            return base.redis.StringLength(key);
        }

        /// 
        /// 数字增长val,返回自增后的值
        /// 
        /// 
        /// 可以为负
        /// 增长后的值
        public double StringIncrement(string key, double val = 1)
        {
            key = AddSysCustomKey(key);
            return base.redis.StringIncrement(key, val);
        }

        /// 
        /// 数字减少val,返回自减少的值
        /// 
        /// 
        /// 可以为负
        /// 减少后的值
        public double StringDecrement(string key, double val = 1)
        {
            key = AddSysCustomKey(key);
            return base.redis.StringDecrement(key, val);
        }

        #endregion

        #region 异步方法
        /// 
        /// 异步方法 保存单个key value
        /// 
        /// Redis Key
        /// 保存的值
        /// 过期时间
        /// 
        public async Task<bool> StringSetAsync(string key, string value, TimeSpan? expiry = default(TimeSpan?))
        {
            key = AddSysCustomKey(key);
            return await base.redis.StringSetAsync(key, value, expiry);
        }
        /// 
        /// 异步方法 添加多个key/value
        /// 
        /// key/value集合
        /// 
        public async Task<bool> StringSetAsync(Dictionary<string, string> valueList)
        {
            var newkeyValues = valueList.Select(p => new KeyValuePair<RedisKey, RedisValue>(AddSysCustomKey(p.Key), p.Value)).ToArray();
            return await base.redis.StringSetAsync(newkeyValues);
        }

        /// 
        /// 异步方法 保存一个对象
        /// 
        /// 对象类型
        /// 保存的Key名称
        /// 对象实体
        /// 过期时间
        /// 
        public async Task<bool> StringSetAsync<T>(string key, T obj, TimeSpan? expiry = default(TimeSpan?))
        {
            key = AddSysCustomKey(key);
            string jsonValue = ConvertJson(obj);
            return await base.redis.StringSetAsync(key, jsonValue, expiry);
        }

        /// 
        /// 异步方法 在原有key的value值之后追加value
        /// 
        /// 追加的Key名称
        /// 追加的值
        /// 
        public async Task<long> StringAppendAsync(string key, string value)
        {
            key = AddSysCustomKey(key);
            return await base.redis.StringAppendAsync(key, value);
        }

        /// 
        /// 异步方法 获取单个key的值
        /// 
        /// 要读取的Key名称
        /// 
        public async Task<string> StringGetAsync(string key)
        {
            key = AddSysCustomKey(key);
            return await base.redis.StringGetAsync(key);
        }

        /// 
        /// 异步方法 获取多个key的value值
        /// 
        /// 要获取值的Key集合
        /// 
        public async Task<List<string>> StringGetAsync(params string[] keys)
        {
            var newKeys = ConvertRedisKeysAddSysCustomKey(keys);
            var values = await base.redis.StringGetAsync(newKeys);
            return values.Select(o => o.ToString()).ToList();
        }


        /// 
        /// 异步方法 获取单个key的value值
        /// 
        /// 返回数据类型
        /// 要获取值的Key集合
        /// 
        public async Task<T> StringGetAsync<T>(string key)
        {
            key = AddSysCustomKey(key);
            var values = await base.redis.StringGetAsync(key);
            return ConvertObj<T>(values);
        }

        /// 
        /// 异步方法 获取多个key的value值
        /// 
        /// 返回数据类型
        /// 要获取值的Key集合
        /// 
        public async Task<List<T>> StringGetAsync<T>(params string[] keys)
        {
            var newKeys = ConvertRedisKeysAddSysCustomKey(keys);
            var values = await base.redis.StringGetAsync(newKeys);
            return ConvetList<T>(values);
        }

        /// 
        /// 异步方法 获取旧值赋上新值
        /// 
        /// Key名称
        /// 新值
        /// 
        public async Task<string> StringGetSetAsync(string key, string value)
        {
            key = AddSysCustomKey(key);
            return await base.redis.StringGetSetAsync(key, value);
        }

        /// 
        /// 异步方法 获取旧值赋上新值
        /// 
        /// 数据类型
        /// Key名称
        /// 新值
        /// 
        public async Task<T> StringGetSetAsync<T>(string key, T value)
        {
            key = AddSysCustomKey(key);
            string jsonValue = ConvertJson(value);
            var oValue = await base.redis.StringGetSetAsync(key, jsonValue);
            return ConvertObj<T>(oValue);
        }


        /// 
        /// 异步方法 获取值的长度
        /// 
        /// Key名称
        /// 
        public async Task<long> StringGetLengthAsync(string key)
        {
            key = AddSysCustomKey(key);
            return await base.redis.StringLengthAsync(key);
        }

        /// 
        /// 异步方法 数字增长val,返回自增后的值
        /// 
        /// 
        /// 可以为负
        /// 增长后的值
        public async Task<double> StringIncrementAsync(string key, double val = 1)
        {
            key = AddSysCustomKey(key);
            return await base.redis.StringIncrementAsync(key, val);
        }

        /// 
        /// 异步方法 数字减少val,返回自减少的值
        /// 
        /// 
        /// 可以为负
        /// 减少后的值
        public async Task<double> StringDecrementAsync(string key, double val = 1)
        {
            key = AddSysCustomKey(key);
            return await base.redis.StringDecrementAsync(key, val);
        }

        #endregion
    }

你可能感兴趣的:(redis数据库,redis)