C# 操作redis

1.安装redis操作工具包,ServiceStack.Redis

2.在App.config/web.config配置Redis信息

  <configSections>
    <section name="RedisConfig" type="redisDemo.redis.RedisConfig,redisDemo" />
  </configSections>
  <RedisConfig WriteServerConStr="10.10.22.37:6379" ReadServerConStr="10.10.22.37:6379" 
               MaxWritePoolSize="60" MaxReadPoolSize="60" AutoStart="true" RecordeLog="false">
  </RedisConfig>

3.配置redis类库

    3.1 RedisManager 管理器,初始化redis连接

    public class RedisManager
    {
        /// <summary>
        /// redis配置文件信息
        /// </summary>
        private static RedisConfig RedisConfig = RedisConfig.GetConfig();

        private static PooledRedisClientManager prcm;

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

        /// <summary>
        /// 创建链接池管理对象
        /// </summary>
        private static void CreateManager()
        {
            string[] WriteServerConStr = SplitString(RedisConfig.WriteServerConStr, ",");
            string[] ReadServerConStr = SplitString(RedisConfig.ReadServerConStr, ",");
            prcm = new PooledRedisClientManager(ReadServerConStr, WriteServerConStr,
                             new RedisClientManagerConfig
                             {
                                 MaxWritePoolSize = RedisConfig.MaxWritePoolSize,
                                 MaxReadPoolSize = RedisConfig.MaxReadPoolSize,
                                 AutoStart = RedisConfig.AutoStart,
                             });
        }

        private static string[] SplitString(string strSource, string split)
        {
            return strSource.Split(split.ToArray());
        }
        /// <summary>
        /// 客户端缓存操作对象
        /// </summary>
        public static IRedisClient GetClient()
        {
            if (prcm == null)
                CreateManager();
            return prcm.GetClient();
        }
    }

    3.2 RedisConfig Redis配置类,用于读取Redis配置信息(App.config)

    public class RedisConfig : ConfigurationSection
    {
        public static RedisConfig GetConfig()
        {
            RedisConfig section = GetConfig("RedisConfig");
            return section;
        }
        public static RedisConfig GetConfig(string sectionName)
        {

            RedisConfig section = (RedisConfig)ConfigurationManager.GetSection(sectionName);
            if (section == null)
                throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
            return section;
        }

        /// <summary>
        /// 可写的Redis链接地址
        /// </summary>
        [ConfigurationProperty("WriteServerConStr", IsRequired = false)]
        public string WriteServerConStr
        {
            get
            {
                return (string)base["WriteServerConStr"];
            }
            set
            {
                base["WriteServerConStr"] = value;
            }
        }


        /// <summary>
        /// 可读的Redis链接地址
        /// </summary>
        [ConfigurationProperty("ReadServerConStr", IsRequired = false)]
        public string ReadServerConStr
        {
            get
            {
                return (string)base["ReadServerConStr"];
            }
            set
            {
                base["ReadServerConStr"] = value;
            }
        }
        /// <summary>
        /// 最大写链接数
        /// </summary>
        [ConfigurationProperty("MaxWritePoolSize", IsRequired = false, DefaultValue = 5)]
        public int MaxWritePoolSize
        {
            get
            {
                int _maxWritePoolSize = (int)base["MaxWritePoolSize"];
                return _maxWritePoolSize > 0 ? _maxWritePoolSize : 5;
            }
            set
            {
                base["MaxWritePoolSize"] = value;
            }
        }


        /// <summary>
        /// 最大读链接数
        /// </summary>
        [ConfigurationProperty("MaxReadPoolSize", IsRequired = false, DefaultValue = 5)]
        public int MaxReadPoolSize
        {
            get
            {
                int _maxReadPoolSize = (int)base["MaxReadPoolSize"];
                return _maxReadPoolSize > 0 ? _maxReadPoolSize : 5;
            }
            set
            {
                base["MaxReadPoolSize"] = value;
            }
        }


        /// <summary>
        /// 自动重启
        /// </summary>
        [ConfigurationProperty("AutoStart", IsRequired = false, DefaultValue = true)]
        public bool AutoStart
        {
            get
            {
                return (bool)base["AutoStart"];
            }
            set
            {
                base["AutoStart"] = value;
            }
        }



        /// <summary>
        /// 本地缓存到期时间,单位:秒
        /// </summary>
        [ConfigurationProperty("LocalCacheTime", IsRequired = false, DefaultValue = 36000)]
        public int LocalCacheTime
        {
            get
            {
                return (int)base["LocalCacheTime"];
            }
            set
            {
                base["LocalCacheTime"] = value;
            }
        }


        /// <summary>
        /// 是否记录日志,该设置仅用于排查redis运行时出现的问题,如redis工作正常,请关闭该项
        /// </summary>
        [ConfigurationProperty("RecordeLog", IsRequired = false, DefaultValue = false)]
        public bool RecordeLog
        {
            get
            {
                return (bool)base["RecordeLog"];
            }
            set
            {
                base["RecordeLog"] = value;
            }
        }
    }

    3.3 RedisBase 封装redis操作基类c

    /// <summary>
    /// RedisBase类,是redis操作的基类,继承自IDisposable接口,主要用于释放内存
    /// </summary>
    public abstract class RedisBase : IDisposable
    {

        public static IRedisClient client { get; private set; }
        private bool _disposed = false;
        static RedisBase()
        {
            client = RedisManager.GetClient();
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!this._disposed)
            {
                if (disposing)
                {
                    client.Dispose();
                    client = null;
                }
            }
            this._disposed = true;
        }
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// 保存数据DB文件到硬盘
        /// </summary>
        public void Save()
        {
            client.Save();
        }
        /// <summary>
        /// 异步保存数据DB文件到硬盘
        /// </summary>
        public void SaveAsync()
        {
            client.SaveAsync();
        }
    }

    3.4 RedisClient redis客户端操作类,封装的基本的增删改查的操作

   public class RedisClient : RedisBase
    {

        public bool Add<T>(string key, T value)
        {
            return client.Add<T>(key, value);
        }

        public bool Add<T>(string key, T value, System.DateTime expiresAt)
        {
            return client.Add<T>(key, value, expiresAt);
        }

        public bool Add<T>(string key, T value, System.TimeSpan expiresIn)
        {
            return client.Add<T>(key, value, expiresIn);
        }

        public long Decrement(string key, uint amount)
        {
            return client.Decrement(key, amount);
        }

        public void FlushAll()
        {
            client.FlushAll();
        }

        public T Get<T>(string key)
        {
            return client.Get<T>(key);
        }

        public IDictionary<string, T> GetAll<T>(IEnumerable<string> keys)
        {
            return client.GetAll<T>(keys);
        }

        public long Increment(string key, uint amount)
        {
            return client.Increment(key, amount);
        }

        public bool Remove(string key)
        {
            return client.Remove(key);
        }

        public void RemoveAll(IEnumerable<string> keys)
        {
            client.RemoveAll(keys);
        }

        public bool Replace<T>(string key, T value)
        {
            return client.Replace<T>(key, value);
        }

        public bool Replace<T>(string key, T value, System.DateTime expiresAt)
        {
            return client.Replace<T>(key, value, expiresAt);
        }

        public bool Replace<T>(string key, T value, System.TimeSpan expiresIn)
        {
            return client.Replace<T>(key, value, expiresIn);
        }

        public bool Set<T>(string key, T value)
        {
            return client.Set<T>(key, value);
        }

        public bool Set<T>(string key, T value, System.DateTime expiresAt)
        {
            return client.Set<T>(key, value, expiresAt);
        }

        public bool Set<T>(string key, T value, System.TimeSpan expiresIn)
        {
            return client.Set<T>(key, value, expiresIn);
        }

        public void SetAll<T>(IDictionary<string, T> values)
        {
            client.SetAll<T>(values);
        }

        public void Dispose()
        {
            client.Dispose();
        }

        public void Delete<T>(T entity) where T : class, new()
        {
            client.Delete<T>(entity);
        }

        public void DeleteAll<TEntity>() where TEntity : class, new()
        {
            client.DeleteAll<TEntity>();
        }

        public void DeleteById<T>(object id) where T : class, new()
        {
            client.DeleteById<T>(id);
        }

        public void DeleteByIds<T>(System.Collections.ICollection ids) where T : class, new()
        {
            client.DeleteById<T>(ids);
        }

        public T GetById<T>(object id) where T : class, new()
        {
            return client.GetById<T>(id);
        }

        public IList<T> GetByIds<T>(System.Collections.ICollection ids) where T : class, new()
        {
            return client.GetByIds<T>(ids);
        }

        public T Store<T>(T entity) where T : class, new()
        {
            return client.Store<T>(entity);
        }

        public void StoreAll<TEntity>(IEnumerable<TEntity> entities) where TEntity : class, new()
        {
            client.StoreAll<TEntity>(entities);
        }

        public void AddItemToList(string listId, string value)
        {
            client.AddItemToList(listId, value);
        }

        public void AddItemToSet(string setId, string item)
        {
            client.AddItemToSet(setId, item);
        }

        public bool AddItemToSortedSet(string setId, string value)
        {
            return client.AddItemToSortedSet(setId, value);
        }

        public bool AddItemToSortedSet(string setId, string value, double score)
        {
            return client.AddItemToSortedSet(setId, value, score);
        }

        public void AddRangeToList(string listId, List<string> values)
        {
            client.AddRangeToList(listId, values);
        }

        public void AddRangeToSet(string setId, List<string> items)
        {
            client.AddRangeToSet(setId, items);
        }

        public bool AddRangeToSortedSet(string setId, List<string> values, double score)
        {
            return client.AddRangeToSortedSet(setId, values, score);
        }

        public bool AddRangeToSortedSet(string setId, List<string> values, long score)
        {
            return client.AddRangeToSortedSet(setId, values, score);
        }

        public long AppendToValue(string key, string value)
        {
            return client.AppendToValue(key, value);
        }

        public string BlockingDequeueItemFromList(string listId, System.TimeSpan? timeOut)
        {
            return client.BlockingDequeueItemFromList(listId, timeOut);
        }

        public KeyValuePair<string, string> BlockingDequeueItemFromLists(string[] listIds, System.TimeSpan? timeOut)
        {
            ItemRef item = client.BlockingDequeueItemFromLists(listIds, timeOut);
            return new KeyValuePair<string, string>(item.Id, item.Item);
        }

        public string BlockingPopAndPushItemBetweenLists(string fromListId, string toListId, System.TimeSpan? timeOut)
        {
            return client.BlockingPopAndPushItemBetweenLists(fromListId, toListId, timeOut);
        }

        public string BlockingPopItemFromList(string listId, System.TimeSpan? timeOut)
        {
            return client.BlockingPopItemFromList(listId, timeOut);
        }

        public KeyValuePair<string, string> BlockingPopItemFromLists(string[] listIds, System.TimeSpan? timeOut)
        {
            ItemRef item = client.BlockingPopItemFromLists(listIds, timeOut);
            return new KeyValuePair<string, string>(item.Id, item.Item);
        }

        public string BlockingRemoveStartFromList(string listId, System.TimeSpan? timeOut)
        {
            return client.BlockingRemoveStartFromList(listId, timeOut);
        }

        public KeyValuePair<string, string> BlockingRemoveStartFromLists(string[] listIds, System.TimeSpan? timeOut)
        {
            ItemRef item = client.BlockingRemoveStartFromLists(listIds, timeOut);
            return new KeyValuePair<string, string>(item.Id, item.Item);
        }

        public bool ContainsKey(string key)
        {
            return client.ContainsKey(key);
        }

        public long DecrementValue(string key)
        {
            return client.DecrementValue(key);
        }

        public long DecrementValueBy(string key, int count)
        {
            return client.DecrementValueBy(key, count);
        }

        public string DequeueItemFromList(string listId)
        {
            return client.DequeueItemFromList(listId);
        }

        public void EnqueueItemOnList(string listId, string value)
        {
            client.EnqueueItemOnList(listId, value);
        }

        public bool ExpireEntryAt(string key, System.DateTime expireAt)
        {
            return client.ExpireEntryAt(key, expireAt);
        }

        public bool ExpireEntryIn(string key, System.TimeSpan expireIn)
        {
            return client.ExpireEntryIn(key, expireIn);
        }

        public Dictionary<string, string> GetAllEntriesFromHash(string hashId)
        {
            return client.GetAllEntriesFromHash(hashId);
        }

        public List<string> GetAllItemsFromList(string listId)
        {
            return client.GetAllItemsFromList(listId);
        }

        public HashSet<string> GetAllItemsFromSet(string setId)
        {
            return client.GetAllItemsFromSet(setId);
        }

        public List<string> GetAllItemsFromSortedSet(string setId)
        {
            return client.GetAllItemsFromSortedSet(setId);
        }

        public List<string> GetAllItemsFromSortedSetDesc(string setId)
        {
            return client.GetAllItemsFromSortedSetDesc(setId);
        }

        public List<string> GetAllKeys()
        {
            return client.GetAllKeys();
        }

        public IDictionary<string, double> GetAllWithScoresFromSortedSet(string setId)
        {
            return client.GetAllWithScoresFromSortedSet(setId);
        }

        //public string GetAndSetEntry(string key, string value)
        //{
        //    return client.GetAndSetEntry(key, value);
        //}

        public HashSet<string> GetDifferencesFromSet(string fromSetId, params string[] withSetIds)
        {
            return client.GetDifferencesFromSet(fromSetId, withSetIds);
        }

        public T GetFromHash<T>(object id)
        {
            return client.GetFromHash<T>(id);
        }

        public long GetHashCount(string hashId)
        {
            return client.GetHashCount(hashId);
        }

        public List<string> GetHashKeys(string hashId)
        {
            return client.GetHashKeys(hashId);
        }

        public List<string> GetHashValues(string hashId)
        {
            return client.GetHashValues(hashId);
        }

        public HashSet<string> GetIntersectFromSets(params string[] setIds)
        {
            return client.GetIntersectFromSets(setIds);
        }

        public string GetItemFromList(string listId, int listIndex)
        {
            return client.GetItemFromList(listId, listIndex);
        }

        public long GetItemIndexInSortedSet(string setId, string value)
        {
            return client.GetItemIndexInSortedSet(setId, value);
        }

        public long GetItemIndexInSortedSetDesc(string setId, string value)
        {
            return client.GetItemIndexInSortedSetDesc(setId, value);
        }

        public double GetItemScoreInSortedSet(string setId, string value)
        {
            return client.GetItemScoreInSortedSet(setId, value);
        }

        public long GetListCount(string listId)
        {
            return client.GetListCount(listId);
        }

        public string GetRandomItemFromSet(string setId)
        {
            return client.GetRandomItemFromSet(setId);
        }

        public List<string> GetRangeFromList(string listId, int startingFrom, int endingAt)
        {
            return client.GetRangeFromList(listId, startingFrom, endingAt);
        }

        public List<string> GetRangeFromSortedList(string listId, int startingFrom, int endingAt)
        {
            return client.GetRangeFromSortedList(listId, startingFrom, endingAt);
        }

        public List<string> GetRangeFromSortedSet(string setId, int fromRank, int toRank)
        {
            return client.GetRangeFromSortedSet(setId, fromRank, toRank);
        }

        public List<string> GetRangeFromSortedSetByHighestScore(string setId, double fromScore, double toScore)
        {
            return client.GetRangeFromSortedSetByHighestScore(setId, fromScore, toScore);
        }

        public List<string> GetRangeFromSortedSetByHighestScore(string setId, long fromScore, long toScore)
        {
            return client.GetRangeFromSortedSetByHighestScore(setId, fromScore, toScore);
        }

        public List<string> GetRangeFromSortedSetByHighestScore(string setId, string fromStringScore, string toStringScore)
        {
            return client.GetRangeFromSortedSetByHighestScore(setId, fromStringScore, toStringScore);
        }

        public List<string> GetRangeFromSortedSetByHighestScore(string setId, double fromScore, double toScore, int? skip, int? take)
        {
            return client.GetRangeFromSortedSetByHighestScore(setId, fromScore, toScore, skip, take);
        }

        public List<string> GetRangeFromSortedSetByHighestScore(string setId, long fromScore, long toScore, int? skip, int? take)
        {
            return client.GetRangeFromSortedSetByHighestScore(setId, fromScore, toScore, skip, take);
        }

        public List<string> GetRangeFromSortedSetByHighestScore(string setId, string fromStringScore, string toStringScore, int? skip, int? take)
        {
            return client.GetRangeFromSortedSetByHighestScore(setId, fromStringScore, toStringScore, skip, take);
        }

        public List<string> GetRangeFromSortedSetByLowestScore(string setId, double fromScore, double toScore)
        {
            return client.GetRangeFromSortedSetByLowestScore(setId, fromScore, toScore);
        }

        public List<string> GetRangeFromSortedSetByLowestScore(string setId, long fromScore, long toScore)
        {
            return client.GetRangeFromSortedSetByLowestScore(setId, fromScore, toScore);
        }

        public List<string> GetRangeFromSortedSetByLowestScore(string setId, string fromStringScore, string toStringScore)
        {
            return client.GetRangeFromSortedSetByLowestScore(setId, fromStringScore, toStringScore);
        }

        public List<string> GetRangeFromSortedSetByLowestScore(string setId, double fromScore, double toScore, int? skip, int? take)
        {
            return client.GetRangeFromSortedSetByLowestScore(setId, fromScore, toScore, skip, take);
        }

        public List<string> GetRangeFromSortedSetByLowestScore(string setId, long fromScore, long toScore, int? skip, int? take)
        {
            return client.GetRangeFromSortedSetByLowestScore(setId, fromScore, toScore, skip, take);
        }

        public List<string> GetRangeFromSortedSetByLowestScore(string setId, string fromStringScore, string toStringScore, int? skip, int? take)
        {
            return client.GetRangeFromSortedSetByLowestScore(setId, fromStringScore, toStringScore, skip, take);
        }

        public List<string> GetRangeFromSortedSetDesc(string setId, int fromRank, int toRank)
        {
            return client.GetRangeFromSortedSetDesc(setId, fromRank, toRank);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSet(string setId, int fromRank, int toRank)
        {
            return client.GetRangeWithScoresFromSortedSet(setId, fromRank, toRank);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string setId, double fromScore, double toScore)
        {
            return client.GetRangeWithScoresFromSortedSetByHighestScore(setId, fromScore, toScore);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string setId, long fromScore, long toScore)
        {
            return client.GetRangeWithScoresFromSortedSetByHighestScore(setId, fromScore, toScore);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string setId, string fromStringScore, string toStringScore)
        {
            return client.GetRangeWithScoresFromSortedSetByHighestScore(setId, fromStringScore, toStringScore);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string setId, double fromScore, double toScore, int? skip, int? take)
        {
            return client.GetRangeWithScoresFromSortedSetByHighestScore(setId, fromScore, toScore, skip, take);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string setId, long fromScore, long toScore, int? skip, int? take)
        {
            return client.GetRangeWithScoresFromSortedSetByHighestScore(setId, fromScore, toScore, skip, take);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string setId, string fromStringScore, string toStringScore, int? skip, int? take)
        {
            return client.GetRangeWithScoresFromSortedSetByHighestScore(setId, fromStringScore, toStringScore, skip, take);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string setId, double fromScore, double toScore)
        {
            return client.GetRangeWithScoresFromSortedSetByHighestScore(setId, fromScore, toScore);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string setId, long fromScore, long toScore)
        {
            return client.GetRangeWithScoresFromSortedSetByLowestScore(setId, fromScore, toScore);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string setId, string fromStringScore, string toStringScore)
        {
            return client.GetRangeWithScoresFromSortedSetByLowestScore(setId, fromStringScore, toStringScore);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string setId, double fromScore, double toScore, int? skip, int? take)
        {
            return client.GetRangeWithScoresFromSortedSetByLowestScore(setId, fromScore, toScore, skip, take);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string setId, long fromScore, long toScore, int? skip, int? take)
        {
            return client.GetRangeWithScoresFromSortedSetByLowestScore(setId, fromScore, toScore, skip, take);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string setId, string fromStringScore, string toStringScore, int? skip, int? take)
        {
            return client.GetRangeWithScoresFromSortedSetByLowestScore(setId, fromStringScore, toStringScore, skip, take);
        }

        public IDictionary<string, double> GetRangeWithScoresFromSortedSetDesc(string setId, int fromRank, int toRank)
        {
            return client.GetRangeWithScoresFromSortedSetDesc(setId, fromRank, toRank);
        }

        public long GetSetCount(string setId)
        {
            return client.GetSetCount(setId);
        }

        public List<string> GetSortedEntryValues(string key, int startingFrom, int endingAt)
        {
            return client.GetSortedEntryValues(key, startingFrom, endingAt);
        }

        public long GetSortedSetCount(string setId)
        {
            return client.GetSortedSetCount(setId);
        }

        public long GetSortedSetCount(string setId, double fromScore, double toScore)
        {
            return client.GetSortedSetCount(setId, fromScore, toScore);
        }

        public long GetSortedSetCount(string setId, long fromScore, long toScore)
        {
            return client.GetSortedSetCount(setId, fromScore, toScore);
        }

        public long GetSortedSetCount(string setId, string fromStringScore, string toStringScore)
        {
            return client.GetSortedSetCount(setId, fromStringScore, toStringScore);
        }

        //public TimeSpan GetTimeToLive(string key)
        //{
        //    return client.GetTimeToLive(key);
        //}

        public HashSet<string> GetUnionFromSets(params string[] setIds)
        {
            return client.GetUnionFromSets(setIds);
        }

        public string GetValue(string key)
        {
            return client.GetValue(key);
        }

        public string GetValueFromHash(string hashId, string key)
        {
            return client.GetValueFromHash(hashId, key);
        }

        public List<string> GetValues(List<string> keys)
        {
            return client.GetValues(keys);
        }

        public List<T> GetValues<T>(List<string> keys)
        {
            return client.GetValues<T>(keys);
        }

        public List<string> GetValuesFromHash(string hashId, params string[] keys)
        {
            return client.GetValuesFromHash(hashId, keys);
        }

        public Dictionary<string, T> GetValuesMap<T>(List<string> keys)
        {
            return client.GetValuesMap<T>(keys);
        }

        public Dictionary<string, string> GetValuesMap(List<string> keys)
        {
            return client.GetValuesMap(keys);
        }

        public bool HashContainsEntry(string hashId, string key)
        {
            return client.HashContainsEntry(hashId, key);
        }

        public double IncrementItemInSortedSet(string setId, string value, double incrementBy)
        {
            return client.IncrementItemInSortedSet(setId, value, incrementBy);
        }

        public double IncrementItemInSortedSet(string setId, string value, long incrementBy)
        {
            return client.IncrementItemInSortedSet(setId, value, incrementBy);
        }

        public long IncrementValue(string key)
        {
            return client.IncrementValue(key);
        }

        public long IncrementValueBy(string key, int count)
        {
            return client.IncrementValueBy(key, count);
        }

        public long IncrementValueInHash(string hashId, string key, int incrementBy)
        {
            return client.IncrementValueInHash(hashId, key, incrementBy);
        }

        public void MoveBetweenSets(string fromSetId, string toSetId, string item)
        {
            client.MoveBetweenSets(fromSetId, toSetId, item);
        }

        public string PopAndPushItemBetweenLists(string fromListId, string toListId)
        {
            return client.PopAndPushItemBetweenLists(fromListId, toListId);
        }

        public string PopItemFromList(string listId)
        {
            return client.PopItemFromList(listId);
        }

        public string PopItemFromSet(string setId)
        {
            return client.PopItemFromSet(setId);
        }

        public string PopItemWithHighestScoreFromSortedSet(string setId)
        {
            return client.PopItemWithHighestScoreFromSortedSet(setId);
        }

        public string PopItemWithLowestScoreFromSortedSet(string setId)
        {
            return client.PopItemWithLowestScoreFromSortedSet(setId);
        }

        public void PrependItemToList(string listId, string value)
        {
            client.PrependItemToList(listId, value);
        }

        public void PrependRangeToList(string listId, List<string> values)
        {
            client.PrependRangeToList(listId, values);
        }

        public long PublishMessage(string toChannel, string message)
        {
            return client.PublishMessage(toChannel, message);
        }

        public void PushItemToList(string listId, string value)
        {
            client.PushItemToList(listId, value);
        }

        public void RemoveAllFromList(string listId)
        {
            client.RemoveAllFromList(listId);
        }

        public string RemoveEndFromList(string listId)
        {
            return client.RemoveEndFromList(listId);
        }

        public bool RemoveEntry(params string[] args)
        {
            return client.RemoveEntry(args);
        }

        public bool RemoveEntryFromHash(string hashId, string key)
        {
            return client.RemoveEntryFromHash(hashId, key);
        }

        public long RemoveItemFromList(string listId, string value)
        {
            return client.RemoveItemFromList(listId, value);
        }

        public long RemoveItemFromList(string listId, string value, int noOfMatches)
        {
            return client.RemoveItemFromList(listId, value, noOfMatches);
        }

        public void RemoveItemFromSet(string setId, string item)
        {
            client.RemoveItemFromSet(setId, item);
        }

        public bool RemoveItemFromSortedSet(string setId, string value)
        {
            return client.RemoveItemFromSortedSet(setId, value);
        }

        public long RemoveRangeFromSortedSet(string setId, int minRank, int maxRank)
        {
            return client.RemoveRangeFromSortedSet(setId, minRank, maxRank);
        }

        public long RemoveRangeFromSortedSetByScore(string setId, double fromScore, double toScore)
        {
            return client.RemoveRangeFromSortedSetByScore(setId, fromScore, toScore);
        }

        public long RemoveRangeFromSortedSetByScore(string setId, long fromScore, long toScore)
        {
            return client.RemoveRangeFromSortedSetByScore(setId, fromScore, toScore);
        }

        public string RemoveStartFromList(string listId)
        {
            return client.RemoveStartFromList(listId);
        }

        public void RenameKey(string fromName, string toName)
        {
            client.RenameKey(fromName, toName);
        }

        public List<string> SearchKeys(string pattern)
        {
            return client.SearchKeys(pattern);
        }

        public void SetAll(Dictionary<string, string> map)
        {
            client.SetAll(map);
        }

        public void SetAll(IEnumerable<string> keys, IEnumerable<string> values)
        {
            client.SetAll(keys, values);
        }

        public bool SetContainsItem(string setId, string item)
        {
            return client.SetContainsItem(setId, item);
        }

        //public void SetEntry(string key, string value)
        //{
        //    client.SetEntry(key, value);
        //}

        //public void SetEntry(string key, string value, System.TimeSpan expireIn)
        //{
        //    client.SetEntry(key, value, expireIn);
        //}

        //public bool SetEntryIfNotExists(string key, string value)
        //{
        //    return client.SetEntryIfNotExists(key, value);
        //}

        public bool SetEntryInHash(string hashId, string key, string value)
        {
            return client.SetEntryInHash(hashId, key, value);
        }

        public bool SetEntryInHashIfNotExists(string hashId, string key, string value)
        {
            return client.SetEntryInHashIfNotExists(hashId, key, value);
        }

        public void SetItemInList(string listId, int listIndex, string value)
        {
            client.SetItemInList(listId, listIndex, value);
        }

        public void SetRangeInHash(string hashId, IEnumerable<KeyValuePair<string, string>> keyValuePairs)
        {
            client.SetRangeInHash(hashId, keyValuePairs);
        }

        public bool SortedSetContainsItem(string setId, string value)
        {
            return client.SortedSetContainsItem(setId, value);
        }

        public void StoreAsHash<T>(T entity)
        {
            client.StoreAsHash<T>(entity);
        }

        public void StoreDifferencesFromSet(string intoSetId, string fromSetId, params string[] withSetIds)
        {
            client.StoreDifferencesFromSet(intoSetId, fromSetId, withSetIds);
        }

        public void StoreIntersectFromSets(string intoSetId, params string[] setIds)
        {
            client.StoreIntersectFromSets(intoSetId, setIds);
        }

        public long StoreIntersectFromSortedSets(string intoSetId, params string[] setIds)
        {
            return client.StoreIntersectFromSortedSets(intoSetId, setIds);
        }

        public void StoreUnionFromSets(string intoSetId, params string[] setIds)
        {
            client.StoreUnionFromSets(intoSetId, setIds);
        }

        public long StoreUnionFromSortedSets(string intoSetId, params string[] setIds)
        {
            return client.StoreUnionFromSortedSets(intoSetId, setIds);
        }

        public void TrimList(string listId, int keepStartingFrom, int keepEndingAt)
        {
            client.TrimList(listId, keepStartingFrom, keepEndingAt);
        }

        public System.IDisposable AcquireLock(string key)
        {
            return client.AcquireLock(key);
        }

        public System.IDisposable AcquireLock(string key, System.TimeSpan timeOut)
        {
            return client.AcquireLock(key, timeOut);
        }
}

4.基本操作

var client = new RedisClient();
client.set<string>("name","xiaoqiu");
Console.WriteLine(client.get<string>("name"));

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页