C# 操作redis

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

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

  
    

3.配置redis类库

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

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

        private static PooledRedisClientManager prcm;

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

        /// 
        /// 创建链接池管理对象
        /// 
        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());
        }
        /// 
        /// 客户端缓存操作对象
        /// 
        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;
        }

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


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


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


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



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


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

    3.3 RedisBase 封装redis操作基类c

    /// 
    /// RedisBase类,是redis操作的基类,继承自IDisposable接口,主要用于释放内存
    /// 
    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);
        }
        /// 
        /// 保存数据DB文件到硬盘
        /// 
        public void Save()
        {
            client.Save();
        }
        /// 
        /// 异步保存数据DB文件到硬盘
        /// 
        public void SaveAsync()
        {
            client.SaveAsync();
        }
    }

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

   public class RedisClient : RedisBase
    {

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

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

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

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

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

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

        public IDictionary GetAll(IEnumerable keys)
        {
            return client.GetAll(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 keys)
        {
            client.RemoveAll(keys);
        }

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

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

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

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

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

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

        public void SetAll(IDictionary values)
        {
            client.SetAll(values);
        }

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

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

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

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

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

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

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

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

        public void StoreAll(IEnumerable entities) where TEntity : class, new()
        {
            client.StoreAll(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 values)
        {
            client.AddRangeToList(listId, values);
        }

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

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

        public bool AddRangeToSortedSet(string setId, List 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 BlockingDequeueItemFromLists(string[] listIds, System.TimeSpan? timeOut)
        {
            ItemRef item = client.BlockingDequeueItemFromLists(listIds, timeOut);
            return new KeyValuePair(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 BlockingPopItemFromLists(string[] listIds, System.TimeSpan? timeOut)
        {
            ItemRef item = client.BlockingPopItemFromLists(listIds, timeOut);
            return new KeyValuePair(item.Id, item.Item);
        }

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

        public KeyValuePair BlockingRemoveStartFromLists(string[] listIds, System.TimeSpan? timeOut)
        {
            ItemRef item = client.BlockingRemoveStartFromLists(listIds, timeOut);
            return new KeyValuePair(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 GetAllEntriesFromHash(string hashId)
        {
            return client.GetAllEntriesFromHash(hashId);
        }

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

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

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

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

        public List GetAllKeys()
        {
            return client.GetAllKeys();
        }

        public IDictionary GetAllWithScoresFromSortedSet(string setId)
        {
            return client.GetAllWithScoresFromSortedSet(setId);
        }

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

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

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

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

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

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

        public HashSet 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 GetRangeFromList(string listId, int startingFrom, int endingAt)
        {
            return client.GetRangeFromList(listId, startingFrom, endingAt);
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        public List 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 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 GetValues(List keys)
        {
            return client.GetValues(keys);
        }

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

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

        public Dictionary GetValuesMap(List keys)
        {
            return client.GetValuesMap(keys);
        }

        public Dictionary GetValuesMap(List 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 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 SearchKeys(string pattern)
        {
            return client.SearchKeys(pattern);
        }

        public void SetAll(Dictionary map)
        {
            client.SetAll(map);
        }

        public void SetAll(IEnumerable keys, IEnumerable 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> keyValuePairs)
        {
            client.SetRangeInHash(hashId, keyValuePairs);
        }

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

        public void StoreAsHash(T entity)
        {
            client.StoreAsHash(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("name","xiaoqiu");
Console.WriteLine(client.get("name"));

你可能感兴趣的:(C#)