using Microsoft.Extensions.Options;
using Txgy.RBS.Framework.RedisHelper.Init;
using Txgy.RBS.Framework.RedisHelper.Interface;
namespace Txgy.RBS.Framework.RedisHelper.Service
{
///
/// Sorted Sets是将 Set 中的元素增加了一个权重参数 score,使得集合中的元素能够按 score 进行有序排列
/// 1.带有权重的元素,比如一个游戏的用户得分排行榜
/// 2.比较复杂的数据结构,一般用到的场景不算太多
///
public class RedisZSetService : RedisBase
{
public RedisZSetService(IOptionsMonitor options) : base(options)
{
}
#region 添加
///
/// 添加key/value,默认分数是从1.多*10的9次方以此递增的,自带自增效果
///
public bool Add(string key, string value)
{
return IClient.AddItemToSortedSet(key, value);
}
///
/// 添加key/value,并设置value的分数
///
public bool AddItemToSortedSet(string key, string value, double score)
{
return IClient.AddItemToSortedSet(key, value, score);
}
///
/// 为key添加values集合,values集合中每个value的分数设置为score
///
public bool AddRangeToSortedSet(string key, List values, double score)
{
return IClient.AddRangeToSortedSet(key, values, score);
}
///
/// 为key添加values集合,values集合中每个value的分数设置为score
///
public bool AddRangeToSortedSet(string key, List values, long score)
{
return IClient.AddRangeToSortedSet(key, values, score);
}
#endregion
#region 获取
///
/// 获取key的所有集合
///
public List GetAll(string key)
{
return IClient.GetAllItemsFromSortedSet(key);
}
///
/// 获取key的所有集合,倒叙输出
///
public List GetAllDesc(string key)
{
return IClient.GetAllItemsFromSortedSetDesc(key);
}
///
/// 获取集合,带分数
///
public IDictionary GetAllWithScoresFromSortedSet(string key)
{
return IClient.GetAllWithScoresFromSortedSet(key);
}
///
/// 获取key为value的下标值
///
public long GetItemIndexInSortedSet(string key, string value)
{
return IClient.GetItemIndexInSortedSet(key, value);
}
///
/// 倒叙排列获取key为value的下标值
///
public long GetItemIndexInSortedSetDesc(string key, string value)
{
return IClient.GetItemIndexInSortedSetDesc(key, value);
}
///
/// 获取key为value的分数
///
public double GetItemScoreInSortedSet(string key, string value)
{
return IClient.GetItemScoreInSortedSet(key, value);
}
///
/// 获取key所有集合的数据总数
///
public long GetSortedSetCount(string key)
{
return IClient.GetSortedSetCount(key);
}
///
/// key集合数据从分数为fromscore到分数为toscore的数据总数
///
public long GetSortedSetCount(string key, double fromScore, double toScore)
{
return IClient.GetSortedSetCount(key, fromScore, toScore);
}
///
/// 获取key集合从高分到低分排序数据,分数从fromscore到分数为toscore的数据
///
public List GetRangeFromSortedSetByHighestScore(string key, double fromscore, double toscore)
{
return IClient.GetRangeFromSortedSetByHighestScore(key, fromscore, toscore);
}
///
/// 获取key集合从低分到高分排序数据,分数从fromscore到分数为toscore的数据
///
public List GetRangeFromSortedSetByLowestScore(string key, double fromscore, double toscore)
{
return IClient.GetRangeFromSortedSetByLowestScore(key, fromscore, toscore);
}
///
/// 获取key集合从高分到低分排序数据,分数从fromscore到分数为toscore的数据,带分数
///
public IDictionary GetRangeWithScoresFromSortedSetByHighestScore(string key, double fromscore, double toscore)
{
return IClient.GetRangeWithScoresFromSortedSetByHighestScore(key, fromscore, toscore);
}
///
/// 获取key集合从低分到高分排序数据,分数从fromscore到分数为toscore的数据,带分数
///
public IDictionary GetRangeWithScoresFromSortedSetByLowestScore(string key, double fromscore, double toscore)
{
return IClient.GetRangeWithScoresFromSortedSetByLowestScore(key, fromscore, toscore);
}
///
/// 获取key集合数据,下标从fromRank到分数为toRank的数据
///
public List GetRangeFromSortedSet(string key, int fromRank, int toRank)
{
return IClient.GetRangeFromSortedSet(key, fromRank, toRank);
}
///
/// 获取key集合倒叙排列数据,下标从fromRank到分数为toRank的数据
///
public List GetRangeFromSortedSetDesc(string key, int fromRank, int toRank)
{
return IClient.GetRangeFromSortedSetDesc(key, fromRank, toRank);
}
///
/// 获取key集合数据,下标从fromRank到分数为toRank的数据,带分数
///
public IDictionary GetRangeWithScoresFromSortedSet(string key, int fromRank, int toRank)
{
return IClient.GetRangeWithScoresFromSortedSet(key, fromRank, toRank);
}
///
/// 获取key集合倒叙排列数据,下标从fromRank到分数为toRank的数据,带分数
///
public IDictionary GetRangeWithScoresFromSortedSetDesc(string key, int fromRank, int toRank)
{
return IClient.GetRangeWithScoresFromSortedSetDesc(key, fromRank, toRank);
}
#endregion
#region 删除
///
/// 删除key为value的数据
///
public bool RemoveItemFromSortedSet(string key, string value)
{
return IClient.RemoveItemFromSortedSet(key, value);
}
///
/// 删除下标从minRank到maxRank的key集合数据
///
public long RemoveRangeFromSortedSet(string key, int minRank, int maxRank)
{
return IClient.RemoveRangeFromSortedSet(key, minRank, maxRank);
}
///
/// 删除分数从fromscore到toscore的key集合数据
///
public long RemoveRangeFromSortedSetByScore(string key, double fromscore, double toscore)
{
return IClient.RemoveRangeFromSortedSetByScore(key, fromscore, toscore);
}
///
/// 删除key集合中分数最大的数据
///
public string PopItemWithHighestScoreFromSortedSet(string key)
{
return IClient.PopItemWithHighestScoreFromSortedSet(key);
}
///
/// 删除key集合中分数最小的数据
///
public string PopItemWithLowestScoreFromSortedSet(string key)
{
return IClient.PopItemWithLowestScoreFromSortedSet(key);
}
#endregion
#region 其它
///
/// 判断key集合中是否存在value数据
///
public bool SortedSetContainsItem(string key, string value)
{
return IClient.SortedSetContainsItem(key, value);
}
///
/// 为key集合值为value的数据,分数加scoreby,返回相加后的分数
///
public double IncrementItemInSortedSet(string key, string value, double scoreBy)
{
return IClient.IncrementItemInSortedSet(key, value, scoreBy);
}
///
/// 获取keys多个集合的交集,并把交集添加的newkey集合中,返回交集数据的总数
///
public long StoreIntersectFromSortedSets(string newkey, string[] keys)
{
return IClient.StoreIntersectFromSortedSets(newkey, keys);
}
///
/// 获取keys多个集合的并集,并把并集数据添加到newkey集合中,返回并集数据的总数
///
public long StoreUnionFromSortedSets(string newkey, string[] keys)
{
return IClient.StoreUnionFromSortedSets(newkey, keys);
}
#endregion
}
}