首先引入 ServiceStack.dll ServiceStack.Interfaces.dll ServiceStack.ServiceInterface.dll
具体可在网上搜索下载。
创建 RedisBase.cs 类
public abstract class RedisBase : IDisposable
{
public static IRedisClient Core { get; private set; }
private bool _disposed = false;
static RedisBase()
{
Core = RedisManager.GetClient();
}
protected virtual void Dispose(bool disposing)
{
if (!this._disposed)
{
if (disposing)
{
Core.Dispose();
Core = null;
}
}
this._disposed = true;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
///
/// 保存数据DB文件到硬盘
///
public void Save()
{
Core.Save();
}
///
/// 异步保存数据DB文件到硬盘
///
public void SaveAsync()
{
Core.SaveAsync();
}
}
创建 RedisConfig 类
public sealed class RedisConfig : ConfigurationSection
{
public static string WriteServerConStr
{
get
{
return string.Format("{0},{1}", ConfigurationManager.AppSettings["redis_server_session"], ConfigurationManager.AppSettings["redis_server_session_bak"]);
}
}
public static string ReadServerConStr
{
get
{
return string.Format("{0}", ConfigurationManager.AppSettings["redis_server_session"], ConfigurationManager.AppSettings["redis_server_session_bak"]);
}
}
public static int MaxWritePoolSize
{
get
{
return int.Parse(ConfigurationManager.AppSettings["redis_max_write_pool"]);
}
}
public static int MaxReadPoolSize
{
get
{
return int.Parse(ConfigurationManager.AppSettings["redis_max_read_pool"]);
}
}
public static bool AutoStart
{
get
{
return true;
}
}
}
创建 RedisHash类
public class RedisHash : RedisBase
{
#region 添加
///
/// 向hashid集合中添加key/value
///
public static bool SetEntryInHash(string hashid, string key, string value)
{
return RedisBase.Core.SetEntryInHash(hashid, key, value);
}
///
/// 如果hashid集合中存在key/value则不添加返回false,如果不存在在添加key/value,返回true
///
public static bool SetEntryInHashIfNotExists(string hashid, string key, string value)
{
return RedisBase.Core.SetEntryInHashIfNotExists(hashid, key, value);
}
///
/// 存储对象T t到hash集合中
///
public static void StoreAsHash(T t)
{
//Core.StoreAsHash(t);
}
#endregion
#region 获取
///
/// 获取对象T中ID为id的数据。
///
//public static T GetFromHash(object id)
//{
// //return RedisBase.Core.GetFromHash(id);
//}
///
/// 获取所有hashid数据集的key/value数据集合
///
public static Dictionary GetAllEntriesFromHash(string hashid)
{
return RedisBase.Core.GetAllEntriesFromHash(hashid);
}
///
/// 获取hashid数据集中的数据总数
///
public static long GetHashCount(string hashid)
{
return RedisBase.Core.GetHashCount(hashid);
}
///
/// 获取hashid数据集中所有key的集合
///
public static List GetHashKeys(string hashid)
{
return RedisBase.Core.GetHashKeys(hashid);
}
///
/// 获取hashid数据集中的所有value集合
///
public static List GetHashValues(string hashid)
{
return RedisBase.Core.GetHashValues(hashid);
}
///
/// 获取hashid数据集中,key的value数据
///
public static string GetValueFromHash(string hashid, string key)
{
return RedisBase.Core.GetValueFromHash(hashid, key);
}
///
/// 获取hashid数据集中,多个keys的value集合
///
public static List GetValuesFromHash(string hashid, string[] keys)
{
return RedisBase.Core.GetValuesFromHash(hashid, keys);
}
#endregion
#region 删除
#endregion
///
/// 删除hashid数据集中的key数据
///
public static bool RemoveEntryFromHash(string hashid, string key)
{
return RedisBase.Core.RemoveEntryFromHash(hashid, key);
}
#region 其它
///
/// 判断hashid数据集中是否存在key的数据
///
public static bool HashContainsEntry(string hashid, string key)
{
return RedisBase.Core.HashContainsEntry(hashid, key);
}
///
/// 给hashid数据集key的value加countby,返回相加后的数据
///
//public static double IncrementValueInHash(string hashid, string key, double countBy)
//{
// return RedisBase.Core.IncrementValueInHash(hashid, key, countBy);
//}
#endregion
}
创建 RedisHelper 类
public class RedisHelper
{
private static readonly PooledRedisClientManager pool = null;
private static readonly string[] redisHosts = null;
public static int RedisMaxReadPool = int.Parse(ConfigurationManager.AppSettings["redis_max_read_pool"]);
public static int RedisMaxWritePool = int.Parse(ConfigurationManager.AppSettings["redis_max_write_pool"]);
///
/// 初始化
///
static RedisHelper()
{
var redisHostStr = ConfigurationManager.AppSettings["redis_server_session"];
if (!string.IsNullOrEmpty(redisHostStr))
{
redisHosts = redisHostStr.Split(',');
if (redisHosts.Length > 0)
{
pool = new PooledRedisClientManager(redisHosts, redisHosts,
new RedisClientManagerConfig()
{
MaxWritePoolSize = RedisMaxWritePool,
MaxReadPoolSize = RedisMaxReadPool,
AutoStart = true
});
}
}
}
///
/// 添加对象到缓存中
///
/// 类型
/// key
/// 值
/// 有效期
/// true成功/false失败
public static bool Add(string key, T value, DateTime expiry)
{
if (value == null)
{
return false;
}
if (expiry <= DateTime.Now)
{
Remove(key);
}
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = 1000;
return r.Set(key, value, expiry - DateTime.Now);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2},异常信息{3}", "cache", "删除", key, ex.Message);
return false;
}
return false;
}
///
/// 添加对象到缓存中
///
/// 添加
///
///
/// 过期时间
public static bool Add(string key, T value, TimeSpan slidingExpiration)
{
if (value == null)
{
return false;
}
if (slidingExpiration.TotalSeconds <= 0)
{
Remove(key);
}
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = 1000;
return r.Set(key, value, slidingExpiration);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2},异常信息{3}", "cache", "删除", key, ex.Message);
return false;
}
return false;
}
///
/// 根据Key获取Value
///
///
///
///
public static T Get(string key)
{
if (string.IsNullOrEmpty(key))
{
return default(T);
}
T obj = default(T);
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = 1000;
obj = r.Get(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2},异常信息{3}", "cache", "删除", key, ex.Message);
}
return obj;
}
///
/// 根据主键进行移除
///
///
public static bool Remove(string key)
{
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = 1000;
return r.Remove(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2},异常信息{3}", "cache", "删除", key, ex.Message);
return false;
}
return false;
}
///
/// 判断是否存在
///
///
///
public static bool Exists(string key)
{
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = 1000;
return r.ContainsKey(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2},异常信息{3}", "cache", "删除", key, ex.Message);
}
return false;
}
///
/// 续期
///
/// key
/// 续期至
///
public static bool ExpireEntryAt(string key,DateTime dateTime)
{
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = 1000;
return r.ExpireEntryAt(key, dateTime);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2},异常信息{3}", "cache", "续期", key, ex.Message);
}
return false;
}
}
创建 RedisList 类
public class RedisList : RedisBase
{
#region 赋值
///
/// 从左侧向list中添加值
///
public static void LPush(string key, string value)
{
RedisBase.Core.PushItemToList(key, value);
}
///
/// 从左侧向list中添加值,并设置过期时间
///
public static void LPush(string key, string value, DateTime dt)
{
RedisBase.Core.PushItemToList(key, value);
RedisBase.Core.ExpireEntryAt(key, dt);
}
///
/// 从左侧向list中添加值,设置过期时间
///
public static void LPush(string key, string value, TimeSpan sp)
{
RedisBase.Core.PushItemToList(key, value);
RedisBase.Core.ExpireEntryIn(key, sp);
}
///
/// 从左侧向list中添加值
///
public static void RPush(string key, string value)
{
RedisBase.Core.PrependItemToList(key, value);
}
///
/// 从右侧向list中添加值,并设置过期时间
///
public static void RPush(string key, string value, DateTime dt)
{
RedisBase.Core.PrependItemToList(key, value);
RedisBase.Core.ExpireEntryAt(key, dt);
}
///
/// 从右侧向list中添加值,并设置过期时间
///
public static void RPush(string key, string value, TimeSpan sp)
{
RedisBase.Core.PrependItemToList(key, value);
RedisBase.Core.ExpireEntryIn(key, sp);
}
///
/// 添加key/value
///
public static void Add(string key, string value)
{
RedisBase.Core.AddItemToList(key, value);
}
///
/// 添加key/value ,并设置过期时间
///
public static void Add(string key, string value, DateTime dt)
{
RedisBase.Core.AddItemToList(key, value);
RedisBase.Core.ExpireEntryAt(key, dt);
}
///
/// 添加key/value。并添加过期时间
///
public static void Add(string key, string value, TimeSpan sp)
{
RedisBase.Core.AddItemToList(key, value);
RedisBase.Core.ExpireEntryIn(key, sp);
}
///
/// 为key添加多个值
///
public static void Add(string key, List values)
{
RedisBase.Core.AddRangeToList(key, values);
}
///
/// 为key添加多个值,并设置过期时间
///
public static void Add(string key, List values, DateTime dt)
{
RedisBase.Core.AddRangeToList(key, values);
RedisBase.Core.ExpireEntryAt(key, dt);
}
///
/// 为key添加多个值,并设置过期时间
///
public static void Add(string key, List values, TimeSpan sp)
{
RedisBase.Core.AddRangeToList(key, values);
RedisBase.Core.ExpireEntryIn(key, sp);
}
#endregion
#region 获取值
///
/// 获取list中key包含的数据数量
///
public static long Count(string key)
{
return RedisBase.Core.GetListCount(key);
}
///
/// 获取key包含的所有数据集合
///
public static List Get(string key)
{
return RedisBase.Core.GetAllItemsFromList(key);
}
///
/// 获取key中下标为star到end的值集合
///
public static List Get(string key, int star, int end)
{
return RedisBase.Core.GetRangeFromList(key, star, end);
}
#endregion
#region 阻塞命令
///
/// 阻塞命令:从list中keys的尾部移除一个值,并返回移除的值,阻塞时间为sp
///
public static string BlockingPopItemFromList(string key, TimeSpan? sp)
{
return RedisBase.Core.BlockingDequeueItemFromList(key, sp);
}
///
/// 阻塞命令:从list中keys的尾部移除一个值,并返回移除的值,阻塞时间为sp
///
//public static ItemRef BlockingPopItemFromLists(string[] keys, TimeSpan? sp)
//{
// return RedisBase.Core.BlockingPopItemFromLists(keys, sp);
//}
///
/// 阻塞命令:从list中keys的尾部移除一个值,并返回移除的值,阻塞时间为sp
///
public static string BlockingDequeueItemFromList(string key, TimeSpan? sp)
{
return RedisBase.Core.BlockingDequeueItemFromList(key, sp);
}
///
/// 阻塞命令:从list中keys的尾部移除一个值,并返回移除的值,阻塞时间为sp
///
//public static ItemRef BlockingDequeueItemFromLists(string[] keys, TimeSpan? sp)
//{
// return RedisBase.Core.BlockingDequeueItemFromLists(keys, sp);
//}
///
/// 阻塞命令:从list中key的头部移除一个值,并返回移除的值,阻塞时间为sp
///
public static string BlockingRemoveStartFromList(string keys, TimeSpan? sp)
{
return RedisBase.Core.BlockingRemoveStartFromList(keys, sp);
}
///
/// 阻塞命令:从list中key的头部移除一个值,并返回移除的值,阻塞时间为sp
///
//public static ItemRef BlockingRemoveStartFromLists(string[] keys, TimeSpan? sp)
//{
// return RedisBase.Core.BlockingRemoveStartFromLists(keys, sp);
//}
///
/// 阻塞命令:从list中一个fromkey的尾部移除一个值,添加到另外一个tokey的头部,并返回移除的值,阻塞时间为sp
///
//public static string BlockingPopAndPushItemBetweenLists(string fromkey, string tokey, TimeSpan? sp)
//{
// return RedisBase.Core.BlockingPopAndPushItemBetweenLists(fromkey, tokey, sp);
//}
#endregion
#region 删除
///
/// 从尾部移除数据,返回移除的数据
///
public static string PopItemFromList(string key)
{
return RedisBase.Core.PopItemFromList(key);
}
///
/// 移除list中,key/value,与参数相同的值,并返回移除的数量
///
public static long RemoveItemFromList(string key, string value)
{
return RedisBase.Core.RemoveItemFromList(key, value);
}
///
/// 从list的尾部移除一个数据,返回移除的数据
///
public static string RemoveEndFromList(string key)
{
return RedisBase.Core.RemoveEndFromList(key);
}
///
/// 从list的头部移除一个数据,返回移除的值
///
public static string RemoveStartFromList(string key)
{
return RedisBase.Core.RemoveStartFromList(key);
}
#endregion
#region 其它
///
/// 从一个list的尾部移除一个数据,添加到另外一个list的头部,并返回移动的值
///
public static string PopAndPushItemBetweenLists(string fromKey, string toKey)
{
return RedisBase.Core.PopAndPushItemBetweenLists(fromKey, toKey);
}
#endregion
}
创建 RedisManager类
public class RedisManager
{
private static PooledRedisClientManager pooledRedisClientManager;
///
/// 静态构造方法,初始化链接池管理对象
///
static RedisManager()
{
CreateManager();
}
///
/// 创建链接池管理对象PooledRedisClientManager
///
private static void CreateManager()
{
string[] WriteServerConStr = SplitString(RedisConfig.WriteServerConStr, ",");
string[] ReadServerConStr = SplitString(RedisConfig.ReadServerConStr, ",");
pooledRedisClientManager = 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 (pooledRedisClientManager == null)
CreateManager();
return pooledRedisClientManager.GetClient();
}
}
创建 RedisSet类
public class RedisSet : RedisBase
{
#region 添加
///
/// key集合中添加value值
///
public static void Add(string key, string value)
{
RedisBase.Core.AddItemToSet(key, value);
}
///
/// key集合中添加list集合
///
public static void Add(string key, List list)
{
RedisBase.Core.AddRangeToSet(key, list);
}
#endregion
#region 获取
///
/// 随机获取key集合中的一个值
///
public static string GetRandomItemFromSet(string key)
{
return RedisBase.Core.GetRandomItemFromSet(key);
}
///
/// 获取key集合值的数量
///
public static long GetCount(string key)
{
return RedisBase.Core.GetSetCount(key);
}
///
/// 获取所有key集合的值
///
public static HashSet GetAllItemsFromSet(string key)
{
return RedisBase.Core.GetAllItemsFromSet(key);
}
#endregion
#region 删除
///
/// 随机删除key集合中的一个值
///
public static string PopItemFromSet(string key)
{
return RedisBase.Core.PopItemFromSet(key);
}
///
/// 删除key集合中的value
///
public static void RemoveItemFromSet(string key, string value)
{
RedisBase.Core.RemoveItemFromSet(key, value);
}
#endregion
#region 其它
///
/// 从fromkey集合中移除值为value的值,并把value添加到tokey集合中
///
public static void MoveBetweenSets(string fromkey, string tokey, string value)
{
RedisBase.Core.MoveBetweenSets(fromkey, tokey, value);
}
///
/// 返回keys多个集合中的并集,返还hashset
///
public static HashSet GetUnionFromSets(string[] keys)
{
return RedisBase.Core.GetUnionFromSets(keys);
}
///
/// keys多个集合中的并集,放入newkey集合中
///
public static void StoreUnionFromSets(string newkey, string[] keys)
{
RedisBase.Core.StoreUnionFromSets(newkey, keys);
}
///
/// 把fromkey集合中的数据与keys集合中的数据对比,fromkey集合中不存在keys集合中,则把这些不存在的数据放入newkey集合中
///
public static void StoreDifferencesFromSet(string newkey, string fromkey, string[] keys)
{
RedisBase.Core.StoreDifferencesFromSet(newkey, fromkey, keys);
}
#endregion
}
创建 RedisString类
public class RedisString : RedisBase
{
private static object o = new object();
#region 赋值
///
/// 设置key的value
///
public static bool Set(string key, string value)
{
lock (o)
{
return RedisBase.Core.Set(key, value);
}
}
///
/// 设置key的value并设置过期时间
///
public static bool Set(string key, string value, DateTime dt)
{
lock (o)
{
return RedisBase.Core.Set(key, value, dt);
}
}
///
/// 设置key的value并设置过期时间
///
public static bool Set(string key, string value, TimeSpan sp)
{
lock (o)
{
return RedisBase.Core.Set(key, value, sp);
}
}
///
/// 设置多个key/value
///
public static void Set(Dictionary dic)
{
lock (o)
{
RedisBase.Core.SetAll(dic);
}
}
#endregion
#region 追加
///
/// 在原有key的value值之后追加value
///
public static long Append(string key, string value)
{
return RedisBase.Core.AppendToValue(key, value);
}
#endregion
#region 获取值
///
/// 获取key的value值
///
public static string Get(string key)
{
lock (o)
{
return RedisBase.Core.GetValue(key);
}
}
///
/// 获取多个key的value值
///
public static List Get(List keys)
{
lock (o)
{
return RedisBase.Core.GetValues(keys);
}
}
///
/// 获取多个key的value值
///
public static List Get(List keys)
{
return RedisBase.Core.GetValues(keys);
}
#endregion
#region 获取旧值赋上新值
///
/// 获取旧值赋上新值
///
//public string GetAndSetValue(string key, string value)
//{
// return RedisBase.Core.GetAndSetValue(key, value);
//}
#endregion
#region 辅助方法
///
/// 获取值的长度
///
//public static long GetCount(string key)
//{
// return RedisBase.Core.GetStringCount(key);
//}
///
/// 自增1,返回自增后的值
///
public static long Incr(string key)
{
return RedisBase.Core.IncrementValue(key);
}
///
/// 自增count,返回自增后的值
///
//public static double IncrBy(string key, double count)
//{
// return RedisBase.Core.IncrementValueBy(key, count);
//}
///
/// 自减1,返回自减后的值
///
public static long Decr(string key)
{
return RedisBase.Core.DecrementValue(key);
}
///
/// 自减count ,返回自减后的值
///
///
///
///
public static long DecrBy(string key, int count)
{
return RedisBase.Core.DecrementValueBy(key, count);
}
#endregion
}
创建 RedisZSet类
public class RedisZSet : RedisBase
{
#region 添加
///
/// 添加key/value,默认分数是从1.多*10的9次方以此递增的,自带自增效果
///
public static bool AddItemToSortedSet(string key, string value)
{
return RedisBase.Core.AddItemToSortedSet(key, value);
}
///
/// 添加key/value,并设置value的分数
///
public static bool AddItemToSortedSet(string key, string value, double score)
{
return RedisBase.Core.AddItemToSortedSet(key, value, score);
}
///
/// 为key添加values集合,values集合中每个value的分数设置为score
///
public static bool AddRangeToSortedSet(string key, List values, double score)
{
return RedisBase.Core.AddRangeToSortedSet(key, values, score);
}
///
/// 为key添加values集合,values集合中每个value的分数设置为score
///
public static bool AddRangeToSortedSet(string key, List values, long score)
{
return RedisBase.Core.AddRangeToSortedSet(key, values, score);
}
#endregion
#region 获取
///
/// 获取key的所有集合
///
public static List GetAllItemsFromSortedSet(string key)
{
return RedisBase.Core.GetAllItemsFromSortedSet(key);
}
///
/// 获取key的所有集合,倒叙输出
///
public static List GetAllItemsFromSortedSetDesc(string key)
{
return RedisBase.Core.GetAllItemsFromSortedSetDesc(key);
}
///
/// 获取可以的说有集合,带分数
///
public static IDictionary GetAllWithScoresFromSortedSet(string key)
{
return RedisBase.Core.GetAllWithScoresFromSortedSet(key);
}
///
/// 获取key为value的下标值
///
public static long GetItemIndexInSortedSet(string key, string value)
{
return RedisBase.Core.GetItemIndexInSortedSet(key, value);
}
///
/// 倒叙排列获取key为value的下标值
///
public static long GetItemIndexInSortedSetDesc(string key, string value)
{
return RedisBase.Core.GetItemIndexInSortedSetDesc(key, value);
}
///
/// 获取key为value的分数
///
public static double GetItemScoreInSortedSet(string key, string value)
{
return RedisBase.Core.GetItemScoreInSortedSet(key, value);
}
///
/// 获取key所有集合的数据总数
///
public static long GetSortedSetCount(string key)
{
return RedisBase.Core.GetSortedSetCount(key);
}
///
/// key集合数据从分数为fromscore到分数为toscore的数据总数
///
//public static long GetSortedSetCount(string key, double fromScore, double toScore)
//{
// return RedisBase.Core.GetSortedSetCount(key, fromScore, toScore);
//}
///
/// 获取key集合从高分到低分排序数据,分数从fromscore到分数为toscore的数据
///
public static List GetRangeFromSortedSetByHighestScore(string key, double fromscore, double toscore)
{
return RedisBase.Core.GetRangeFromSortedSetByHighestScore(key, fromscore, toscore);
}
///
/// 获取key集合从低分到高分排序数据,分数从fromscore到分数为toscore的数据
///
public static List GetRangeFromSortedSetByLowestScore(string key, double fromscore, double toscore)
{
return RedisBase.Core.GetRangeFromSortedSetByLowestScore(key, fromscore, toscore);
}
///
/// 获取key集合从高分到低分排序数据,分数从fromscore到分数为toscore的数据,带分数
///
public static IDictionary GetRangeWithScoresFromSortedSetByHighestScore(string key, double fromscore, double toscore)
{
return RedisBase.Core.GetRangeWithScoresFromSortedSetByHighestScore(key, fromscore, toscore);
}
///
/// 获取key集合从低分到高分排序数据,分数从fromscore到分数为toscore的数据,带分数
///
public static IDictionary GetRangeWithScoresFromSortedSetByLowestScore(string key, double fromscore, double toscore)
{
return RedisBase.Core.GetRangeWithScoresFromSortedSetByLowestScore(key, fromscore, toscore);
}
///
/// 获取key集合数据,下标从fromRank到分数为toRank的数据
///
public static List GetRangeFromSortedSet(string key, int fromRank, int toRank)
{
return RedisBase.Core.GetRangeFromSortedSet(key, fromRank, toRank);
}
///
/// 获取key集合倒叙排列数据,下标从fromRank到分数为toRank的数据
///
public static List GetRangeFromSortedSetDesc(string key, int fromRank, int toRank)
{
return RedisBase.Core.GetRangeFromSortedSetDesc(key, fromRank, toRank);
}
///
/// 获取key集合数据,下标从fromRank到分数为toRank的数据,带分数
///
public static IDictionary GetRangeWithScoresFromSortedSet(string key, int fromRank, int toRank)
{
return RedisBase.Core.GetRangeWithScoresFromSortedSet(key, fromRank, toRank);
}
///
/// 获取key集合倒叙排列数据,下标从fromRank到分数为toRank的数据,带分数
///
public static IDictionary GetRangeWithScoresFromSortedSetDesc(string key, int fromRank, int toRank)
{
return RedisBase.Core.GetRangeWithScoresFromSortedSetDesc(key, fromRank, toRank);
}
#endregion
#region 删除
///
/// 删除key为value的数据
///
public static bool RemoveItemFromSortedSet(string key, string value)
{
return RedisBase.Core.RemoveItemFromSortedSet(key, value);
}
///
/// 删除下标从minRank到maxRank的key集合数据
///
public static long RemoveRangeFromSortedSet(string key, int minRank, int maxRank)
{
return RedisBase.Core.RemoveRangeFromSortedSet(key, minRank, maxRank);
}
///
/// 删除分数从fromscore到toscore的key集合数据
///
public static long RemoveRangeFromSortedSetByScore(string key, double fromscore, double toscore)
{
return RedisBase.Core.RemoveRangeFromSortedSetByScore(key, fromscore, toscore);
}
///
/// 删除key集合中分数最大的数据
///
public static string PopItemWithHighestScoreFromSortedSet(string key)
{
return RedisBase.Core.PopItemWithHighestScoreFromSortedSet(key);
}
///
/// 删除key集合中分数最小的数据
///
public static string PopItemWithLowestScoreFromSortedSet(string key)
{
return RedisBase.Core.PopItemWithLowestScoreFromSortedSet(key);
}
#endregion
#region 其它
///
/// 判断key集合中是否存在value数据
///
public static bool SortedSetContainsItem(string key, string value)
{
return RedisBase.Core.SortedSetContainsItem(key, value);
}
///
/// 为key集合值为value的数据,分数加scoreby,返回相加后的分数
///
public static double IncrementItemInSortedSet(string key, string value, double scoreBy)
{
return RedisBase.Core.IncrementItemInSortedSet(key, value, scoreBy);
}
///
/// 获取keys多个集合的交集,并把交集添加的newkey集合中,返回交集数据的总数
///
public static long StoreIntersectFromSortedSets(string newkey, string[] keys)
{
return RedisBase.Core.StoreIntersectFromSortedSets(newkey, keys);
}
///
/// 获取keys多个集合的并集,并把并集数据添加到newkey集合中,返回并集数据的总数
///
public static long StoreUnionFromSortedSets(string newkey, string[] keys)
{
return RedisBase.Core.StoreUnionFromSortedSets(newkey, keys);
}
#endregion
}
配置文件: