博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何使用Redis排序列表
阅读量:2507 次
发布时间:2019-05-11

本文共 1303 字,大约阅读时间需要 4 分钟。

A sorted set associates a rank to each item in a set.

排序的集合将等级与集合中的每个项目相关联。

Sorted sets work in a similar way to sets, and they use similar commands, except S is now Z, for example:

排序集合的工作方式与集合类似,并且它们使用类似的命令,但S现在是Z ,例如:

  • SADD -> ZADD

    SADD - > ZADD

  • SPOP -> ZPOP

    SPOP - > ZPOP

But they are slightly different.

但是它们略有不同。

ZADD accepts a score:

ZADD接受分数

ZADD names 1 "Flavio"ZADD names 2 "Syd"ZADD names 2 "Roger"

As you can see, values must still be unique, but now they are associated to a score.

如您所见,值仍然必须是唯一的,但是现在它们已与得分相关联。

The score does not have to be unique.

分数不必是唯一的。

Items in a set are always sorted by the score.

集合中的项目始终按分数排序。

This is very useful to implement some kind of data storage tool like (usual example) a leaderboard. Or to indicate the time some item was added, with a timestamp.

这对于实现某种类型的数据存储工具(例如(页首)排行榜)非常有用。 或指示带有时间戳的添加项目的时间。

You can get the score of an item using ZRANK:

您可以使用ZRANK获取项目的得分:

ZRANK names "Flavio"

List all items in a sorted set using ZRANGE, which works similarly to LRANGE in lists:

使用ZRANGE列出排序集中的所有项目,其作用类似于列表中的LRANGE

ZRANGE names 0 -1

Add WITHSCORES to also return the scores information:

添加WITHSCORES还返回分数信息:

You can increment the score of an item in the set using ZINCRBY.

您可以使用ZINCRBY来增加项目集中的ZINCRBY

See all the sorted sets commands .

查看所有排序的set命令。

翻译自:

转载地址:http://axmgb.baihongyu.com/

你可能感兴趣的文章
iOS 的 XMPPFramework 简介
查看>>
hdu 3555 数位dp入门
查看>>
Git学习系列-Git基本概念
查看>>
c#多个程序集使用app.config 的解决办法
查看>>
模仿网站登录注册
查看>>
Linux+Apache+PHP+MySQL服务器环境配置(CentOS篇)
查看>>
Linux下获取本机IP地址的代码
查看>>
(C#)调用Webservice,提示远程服务器返回错误(500)内部服务器错误
查看>>
flex布局
查看>>
python-----python的文件操作
查看>>
字节流例子
查看>>
Chain Of Responsibility Design Pattern Example
查看>>
Windows下curl使用 转载
查看>>
一个简单最大正向匹配(Maximum Matching)MM中文分词算法的实现
查看>>
angularjs中$scope是什么意思?
查看>>
数据校验
查看>>
控制台输出
查看>>
设计模式(二)单例设计模式
查看>>
iOS之CAKeyframeAnimation关键帧动画详解
查看>>
Spring第三篇【Core模块之对象依赖】
查看>>