• Redis封装值ZSet


    /// <summary>
        /// Sorted Sets是将 Set 中的元素增加了一个权重参数 score,使得集合中的元素能够按 score 进行有序排列
        /// 1.带有权重的元素,比如一个游戏的用户得分排行榜
        /// 2.比较复杂的数据结构,一般用到的场景不算太多
        /// </summary>
        public class RedisZSetService : RedisBase
        {
            #region 添加
            /// <summary>
            /// 添加key/value,默认分数是从1.多*10的9次方以此递增的,自带自增效果
            /// </summary>
            public bool AddItemToSortedSet(string key, string value)
            {
                return RedisBase.iClient.AddItemToSortedSet(key, value);
            }
            /// <summary>
            /// 添加key/value,并设置value的分数
            /// </summary>
            public bool AddItemToSortedSet(string key, string value, double score)
            {
                return RedisBase.iClient.AddItemToSortedSet(key, value, score);
            }
            /// <summary>
            /// 为key添加values集合,values集合中每个value的分数设置为score
            /// </summary>
            public bool AddRangeToSortedSet(string key, List<string> values, double score)
            {
                return RedisBase.iClient.AddRangeToSortedSet(key, values, score);
            }
            /// <summary>
            /// 为key添加values集合,values集合中每个value的分数设置为score
            /// </summary>
            public bool AddRangeToSortedSet(string key, List<string> values, long score)
            {
                return RedisBase.iClient.AddRangeToSortedSet(key, values, score);
            }
            #endregion
    
            #region 获取
            /// <summary>
            /// 获取key的所有集合
            /// </summary>
            public List<string> GetAll(string key)
            {
                return RedisBase.iClient.GetAllItemsFromSortedSet(key);
            }
            /// <summary>
            /// 获取key的所有集合,倒叙输出
            /// </summary>
            public List<string> GetAllDesc(string key)
            {
                return RedisBase.iClient.GetAllItemsFromSortedSetDesc(key);
            }
            /// <summary>
            /// 获取集合,带分数
            /// </summary>
            public IDictionary<string, double> GetAllWithScoresFromSortedSet(string key)
            {
                return RedisBase.iClient.GetAllWithScoresFromSortedSet(key);
            }
            /// <summary>
            /// 获取key为value的下标值
            /// </summary>
            public long GetItemIndexInSortedSet(string key, string value)
            {
                return RedisBase.iClient.GetItemIndexInSortedSet(key, value);
            }
            /// <summary>
            /// 倒叙排列获取key为value的下标值
            /// </summary>
            public long GetItemIndexInSortedSetDesc(string key, string value)
            {
                return RedisBase.iClient.GetItemIndexInSortedSetDesc(key, value);
            }
            /// <summary>
            /// 获取key为value的分数
            /// </summary>
            public double GetItemScoreInSortedSet(string key, string value)
            {
                return RedisBase.iClient.GetItemScoreInSortedSet(key, value);
            }
            /// <summary>
            /// 获取key所有集合的数据总数
            /// </summary>
            public long GetSortedSetCount(string key)
            {
                return RedisBase.iClient.GetSortedSetCount(key);
            }
            /// <summary>
            /// key集合数据从分数为fromscore到分数为toscore的数据总数
            /// </summary>
            public long GetSortedSetCount(string key, double fromScore, double toScore)
            {
                return RedisBase.iClient.GetSortedSetCount(key, fromScore, toScore);
            }
            /// <summary>
            /// 获取key集合从高分到低分排序数据,分数从fromscore到分数为toscore的数据
            /// </summary>
            public List<string> GetRangeFromSortedSetByHighestScore(string key, double fromscore, double toscore)
            {
                return RedisBase.iClient.GetRangeFromSortedSetByHighestScore(key, fromscore, toscore);
            }
            /// <summary>
            /// 获取key集合从低分到高分排序数据,分数从fromscore到分数为toscore的数据
            /// </summary>
            public List<string> GetRangeFromSortedSetByLowestScore(string key, double fromscore, double toscore)
            {
                return RedisBase.iClient.GetRangeFromSortedSetByLowestScore(key, fromscore, toscore);
            }
            /// <summary>
            /// 获取key集合从高分到低分排序数据,分数从fromscore到分数为toscore的数据,带分数
            /// </summary>
            public IDictionary<string, double> GetRangeWithScoresFromSortedSetByHighestScore(string key, double fromscore, double toscore)
            {
                return RedisBase.iClient.GetRangeWithScoresFromSortedSetByHighestScore(key, fromscore, toscore);
            }
            /// <summary>
            ///  获取key集合从低分到高分排序数据,分数从fromscore到分数为toscore的数据,带分数
            /// </summary>
            public IDictionary<string, double> GetRangeWithScoresFromSortedSetByLowestScore(string key, double fromscore, double toscore)
            {
                return RedisBase.iClient.GetRangeWithScoresFromSortedSetByLowestScore(key, fromscore, toscore);
            }
            /// <summary>
            ///  获取key集合数据,下标从fromRank到分数为toRank的数据
            /// </summary>
            public List<string> GetRangeFromSortedSet(string key, int fromRank, int toRank)
            {
                return RedisBase.iClient.GetRangeFromSortedSet(key, fromRank, toRank);
            }
            /// <summary>
            /// 获取key集合倒叙排列数据,下标从fromRank到分数为toRank的数据
            /// </summary>
            public List<string> GetRangeFromSortedSetDesc(string key, int fromRank, int toRank)
            {
                return RedisBase.iClient.GetRangeFromSortedSetDesc(key, fromRank, toRank);
            }
            /// <summary>
            /// 获取key集合数据,下标从fromRank到分数为toRank的数据,带分数
            /// </summary>
            public IDictionary<string, double> GetRangeWithScoresFromSortedSet(string key, int fromRank, int toRank)
            {
                return RedisBase.iClient.GetRangeWithScoresFromSortedSet(key, fromRank, toRank);
            }
            /// <summary>
            ///  获取key集合倒叙排列数据,下标从fromRank到分数为toRank的数据,带分数
            /// </summary>
            public IDictionary<string, double> GetRangeWithScoresFromSortedSetDesc(string key, int fromRank, int toRank)
            {
                return RedisBase.iClient.GetRangeWithScoresFromSortedSetDesc(key, fromRank, toRank);
            }
            #endregion
    
            #region 删除
            /// <summary>
            /// 删除key为value的数据
            /// </summary>
            public bool RemoveItemFromSortedSet(string key, string value)
            {
                return RedisBase.iClient.RemoveItemFromSortedSet(key, value);
            }
            /// <summary>
            /// 删除下标从minRank到maxRank的key集合数据
            /// </summary>
            public long RemoveRangeFromSortedSet(string key, int minRank, int maxRank)
            {
                return RedisBase.iClient.RemoveRangeFromSortedSet(key, minRank, maxRank);
            }
            /// <summary>
            /// 删除分数从fromscore到toscore的key集合数据
            /// </summary>
            public long RemoveRangeFromSortedSetByScore(string key, double fromscore, double toscore)
            {
                return RedisBase.iClient.RemoveRangeFromSortedSetByScore(key, fromscore, toscore);
            }
            /// <summary>
            /// 删除key集合中分数最大的数据
            /// </summary>
            public string PopItemWithHighestScoreFromSortedSet(string key)
            {
                return RedisBase.iClient.PopItemWithHighestScoreFromSortedSet(key);
            }
            /// <summary>
            /// 删除key集合中分数最小的数据
            /// </summary>
            public string PopItemWithLowestScoreFromSortedSet(string key)
            {
                return RedisBase.iClient.PopItemWithLowestScoreFromSortedSet(key);
            }
            #endregion
    
            #region 其它
            /// <summary>
            /// 判断key集合中是否存在value数据
            /// </summary>
            public bool SortedSetContainsItem(string key, string value)
            {
                return RedisBase.iClient.SortedSetContainsItem(key, value);
            }
            /// <summary>
            /// 为key集合值为value的数据,分数加scoreby,返回相加后的分数
            /// </summary>
            public double IncrementItemInSortedSet(string key, string value, double scoreBy)
            {
                return RedisBase.iClient.IncrementItemInSortedSet(key, value, scoreBy);
            }
            /// <summary>
            /// 获取keys多个集合的交集,并把交集添加的newkey集合中,返回交集数据的总数
            /// </summary>
            public long StoreIntersectFromSortedSets(string newkey, string[] keys)
            {
                return RedisBase.iClient.StoreIntersectFromSortedSets(newkey, keys);
            }
            /// <summary>
            /// 获取keys多个集合的并集,并把并集数据添加到newkey集合中,返回并集数据的总数
            /// </summary>
            public long StoreUnionFromSortedSets(string newkey, string[] keys)
            {
                return RedisBase.iClient.StoreUnionFromSortedSets(newkey, keys);
            }
            #endregion
        }
  • 相关阅读:
    Dynamic Method Binding in Delphi 动态方法绑定
    Server Memory Server Configuration Options 服务器内存服务配置选项
    最大化系统并发连接数.Windows.reg
    js一行代码解决各种IE兼容问题
    [原创]如果软件在网络磁盘中或移动磁盘中运行时需要解决 exception C0000006 异常问题
    用 ghostscript 转化PDF文件为图片 的参数设置
    GhostScript应用一例:使用GhostScript强行修改加密PDF
    Win7 Win8 Win10取不到机器码的处理办法
    WCAG
    页面被iframe与无刷新更换url方法
  • 原文地址:https://www.cnblogs.com/marshhu/p/6806359.html
Copyright © 2020-2023  润新知