(エッセンス)2020年8月15日redisデータベースStackExchange.Redisパッケージソース(C#版)


まずnuget:

  • ServiceStack.Redis
  • ServiceStack.Common
  • ServiceStack.interfaces
  • 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 } }

    サービス層:ビッグ5データ構造

    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     
    
        }
       
      

    サービス :ビッグ5データ

    ///   
        /// 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
        }