Redis data type (String, List, Hash, Set, Sorted Set)

Redis data type (String, List, Hash, Set, Sorted Set)

首先登录redis数据库 redis-cli  -p 6379
127.0.0.1:6379> auth 123456 验证密码 #这里我设置了密码的所以需要验证

One, String

Overview : String is the most basic type of redis, which can store up to 512MB of data. String type is binary safe, that is, it can store any data, such as numbers, pictures, serialized objects, etc.

1、SET / GET / APPEND / STRLEN

redis-cli 
redis 127.0.0.1:6379> exists mykey             #判断该键是否存在,存在返回1,否则返回0。
(integer) 0
redis 127.0.0.1:6379> append mykey "hello"     #该键并不存在,因此append命令返回当前Value的长度。
(integer) 5
redis 127.0.0.1:6379> append mykey " world"    #该键已经存在,因此返回追加后Value的总长度。
(integer) 11
redis 127.0.0.1:6379> get mykey                #通过get命令获取该键,以判断append的结果。
"hello world"
redis 127.0.0.1:6379> set mykey "this is a test"   #通过set命令为键设置新值,并覆盖原有值。
OK
redis 127.0.0.1:6379> get mykey
"this is a test"
redis 127.0.0.1:6379> strlen mykey             #获取指定Key的字符长度。
(integer) 14

2、 INCR/DECR/INCRBY/DECRBY

redis 127.0.0.1:6379> set mykey 20           #设置Key的值为20
OK
redis 127.0.0.1:6379> incr mykey             #该Key的值递增1
(integer) 21
redis 127.0.0.1:6379> decr mykey             #该Key的值递减1
(integer) 20
redis 127.0.0.1:6379> del mykey              #删除已有键。返回1说明删除成功
(integer) 1
redis 127.0.0.1:6379> decr mykey             #对空值执行递减操作,其原值被设定为0,递减后的值为-1
(integer) -1
redis 127.0.0.1:6379> del mykey
(integer) 1
redis 127.0.0.1:6379> incr mykey             #对空值执行递增操作,其原值被设定为0,递增后的值为1
(integer) 1
redis 127 .0.0.1:6379> set mykey hello       #将该键的Value设置为不能转换为整型的普通字符串。
OK
redis 127.0.0.1:6379> incr mykey
(error) ERR value is not an integer or out of range 
redis 127.0.0.1:6379> set mykey 10
OK
redis 127.0.0.1:6379> decrby mykey 5         #减少指定的整数
(integer) 5
redis 127.0.0.1:6379> incrby mykey 10        #增加指定的整数
(integer) 15

3 、 GETSET

redis 127.0.0.1:6379> incr mycounter      #将计数器的值原子性的递增1
(integer) 1
redis 127.0.0.1:6379> getset mycounter 0  #在获取计数器原有值的同时,并将其设置为新值,这两个操作原子性的同时完成。
redis 127.0.0.1:6379> get mycounter       #查看设置后的结果。
"0" 

4、SETEX

redis 127.0.0.1:6379> setex mykey 15 "hello"      #设置指定Key的过期时间为15秒。
redis 127.0.0.1:6379> ttl mykey                   #通过tt1命令查看指定Key的剩余存活时间(秒数),0表示已经过期,-1表示永不过期。
(integer) 4
redis 127.0.0.1:6379> get mykey          #在该键的存活期内我们仍然可以获取到它的Value。
"hello"
redis 127.0.0.1:6379> ttl mykey          #该ttl命令的返回值显示,该Key已经过期。
(integer) -2
redis 127.0.0.1:6379> get mykey          #获取已过期的Key将返回nil
(nil)

5、 SETNX

redis 127 .0.0.1:6379> del mykey              #删除该键,以便于下面的测试验证。
(integer) 1
redis 127.0.0.1:6379> setnx mykey "hello"     #该键并不存在,因此setnx命令执行成功。
(integer) 1
redis 127.0.0.1:6379> setnx mykey "world"     #该键已经存在,因此本次设置没有产生任何效果。
(integer) 0
redis 127 .0.0.1:6379> get mykey              #从结果可以看出,返回的值仍为第一次设置的值。
"hello"

6、 MSET/MGET/MSETNX

redis 127.0.0.1:6379> mset key1 "hello" key2 "world"    #批量设置了key1和key2两个键。
redis 127.0.0.1:6379> mget key1 key2                    #批量获取了key1和key2两个键的值。
1) "hello"
2) "world"
redis 127.0.0.1:6379> msetnx key3 "zhang" key4 "san"    #批量设置了key3和key4两个键,因为之前他们并不存在,所以msetnx命令执行成功并返回1。
(integer) 1
redis 127.0.0.1:6379> mget key3 key4
1) "zhang"
2) "san"
redis 127.0.0.1:6379> msetnx key3 "hello" key5 "world"   #批量设置了key3和key5两个键,但是key3已经存在,所以msetnx命令执行失败并返回0。
(integer) 0
redis 127.0.0.1:6379> mget key3 key5          #批量获取key3和key5,由于key5没有设置成功,所以返回nil
1) "zhang"
2) (nil)

Two, List data type

Overview: The element type of the list is string, sorted in the order of insertion, and elements are added to the head or tail of the list

1、 LPUSH/LPUSHX/ LRANGE

redis 127.0.0.1:6379> del mykey 
(integer) 1
redis 127.0.0.1:6379> lpush mykey a b c d
#mykey键并不存在,该命令会创建该键及与其关联的List,之后在将参数中的values从左到右依次插入。
(integer) 4
redis 127.0.0.1:6379> lrange mykey 0 2      #取从位置0开始到位置2结束的3个元素。
1) "d"
2) "c"
3) "b"
redis 127.0.0.1:6379> lrange mykey 0 -1    #取链表中的全部元素,其中0表示第一个元素,-1表示最后一一个元素。
1) "d"
2) "c"
3) "b"
4) "a"
redis 127.0.0.1:6379> lpushx mykey2 e      #mykey2键此时并不存在,因此lpushx命令将不会进行任何操作,其返回值为0。
(integer) 0
redis 127.0.0.1:6379> lrange mykey2 0 -1   #可以看到mykey2没有关联任何List Value。
(empty list or set)
redis 127.0.0.1:6379> lpushx mykey e       #mykey键此时已经存在,所以lpushx命令插入成功,并返回链表中当前元素的数量。
(integer) 5
redis 127.0.0.1:6379> lrange mykey 0 0      #获取该键的List Value的头部元素。
1) "e"

2 、 LPOP / FULL

redis 127.0.0.1:6379> del mykey
(integer) 1
redis 127.0.0.1:6379> lpush mykey a b c d
(integer) 4
redis 127.0.0.1:6379> lpop mykey       #移除并返回mykey键的第一个元素,即从右往左第一个
"d"
redis 127.0.0.1:6379> lpop mykey
"c"
redis 127.0.0.1:6379> llen mykey        #获取表中元素数量,在执行lpop命令两次后,链表头部的两个元素已经被弹出,此时链表中元素的数量是2
(integer) 2

3 、 LREM / LSET / LINDEX / LTRIM

redis 127.0.0.1:6379> del mykey
(integer) 1
redis 127.0.0.1:6379> lpush mykey a b c d a c     #为后面的示例准备测试数据。
(integer) 6
redis 127.0.0.1:6379> lrem mykey 2 a      #从头部(left)向尾部(right)变量链表,删除2个值等于a的元素,返回值为实际删除的数量。
(integer) 2
redis127.0.0.1:6379>lrange mykey 0 -1        #看出删除后链表中的全部元素。
1) "c"
2) "d"
3) "c"
4) "b"
redis 127.0.0.1:6379> lindex mykey 1        #获取索引值为1(头部的第二个元素)的元素值。
"d"
redis 127.0.0.1:6379> lset mykey 1 e        #将索引值为1(头部的第二个元素)的元素值设置为新值e。
OK
redis 127.0.0.1:6379> lindex mykey 1        #查看是否设置成功。
"e"
redis 127.0.0.1:6379> lindex mykey 6        #索引值6超过了链表中元素的数量,该命令返回nil。
(nil)
redis 127.0.0.1:6379> lset mykey 6 hh       #设置的索引值6超过了链表中元素的数量,设置失败,该命令返回错误信息。
(error) ERR index out of range
redis 127 .0.0.1:6379> ltrim mykey 0 2      #仅保留索引值0到2之间的3个元素,注意第0个和第2个元素均被保留。
OK
redis 127.0.0.1:6379> lrange mykey 0 -1     #查看ltrim后的结果。
l) "c"
2) "e"
3) "c"

4 、 LINSERT

redis 127.0.0.1:6379> del mykey     #删除该键便于后面的测试。
(integer) 1
redis 127.0.0.1:6379> lpush mykey a b c d e    #为后面的示例准备测试数据。
(integer) 1
redis 127.0.0.1:6379> linsert mykey before a a1    #在a的前面插入新元素a1。
(integer) 6。
redis 127.0.0.1:6379> lrange mykey 0 -1            #查看是否插入成功,从结果看已经插入
1) "e"
2) "d"
3) "c"
4) "b"
5) "a1"
6) "a"
redis 127.0.0.1:6379> linsert mykey after e e2    #在e的后面插入新元素e2,从返回结果看已经插入成功。
(integer) 7
redis 127.0.0.1:6379> lindex mykey 1       #再次查看是否插入成功。
"e2"
redis 127.0.0.1:6379> linsert mykey after k a    #在不存在的元素之前或之后插入新元素,linsert 命令操作失败,并返回-1。
(integer) -1
redis 127.0.0.1:6379> linsert mykey1 after a a2   #为不存在的Key插入新元素,linsert命 令操作失败,返回0。.
(integer) 0

5、RPUSH/ RPUSHX/RPOP/RPOPLPUSH

redis 127.0.0.1:6379> del mykey   #删除该键,以便于后而的测试。
(integer) 1
redis 127.0.0.1:6379> rpush mykey a b c d  #从链表的尾部插入参数中给出的values,插入顺序是从右到左依次插入。
(integer) 4
redis 127.0.0.1:6379> lrange mykey 0 -1    #通过lrange命令可以获悉rpush在插入多值时的插入顺序。

redis 127.0.0.1:6379> rpushx mykey e      #该键已经存在并且包含4个元素,rpushx命令将执行成功,并将元素e插入到链表的尾部。
(integer) 5
redis 127.0.0.1:6379> lindex mykey 4      #通过lindex命令可以看出之前的rpushx命令确实执行成功,因为索引值为4的元素已经是新元素了。
"e"
redis 127.0.0.1:6379> rpushx mykey2 e    #由于mykey2键并不存在,因此rpushx命令不会插入数据,其返回值为0。
(integer) 0
redis 127.0.0.1:6379> lrange mykey 0 -1   #在执行rpoplpush命令前,先看一下 mykey中链表的元素有哪些,注意他们的位置关系。
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
127. 0.0.1:6379> RPOP mykey       #移除并返回mykey键的第一个元素,从右取
"e"
127.0.0.1:6379> LRANGE mykey 0 -1
1) "a"
2) "b"
3) "c"
4) "d"
redis 127.0.0.1:6379> rpoplpush mykey mykey2   #将mykey的尾部元素e弹出,同时再插入到mykey2的头部(原子性的完成这两步操作)。
"d"
redis 127.0.0.1:6379> lrange mykey 0 -1       #通过lrange命令查看mykey在弹出尾部元素后的结果。
1) "a"
2) "b"
3) "c"
redis 127.0.0.1:6379> lrange mykey2 0 -1     #通过lrange命令查看mykey2在插入元素后的结果。
1) "d"
redis 127.0.0.1:6379> rpoplpush mykey mykey   #将source和destination设为同一键,将mykey中的尾部元素移到其头部。
"c"
redis 127.0.0.1:6379> lrange mykey 0 -1      #查看移动结果。
1) "c"
2) "a"
3) "b"

Three, Hash data type (hash type)

Overview: hash is used to store objects. You can use this naming method: the object category and ID form the key name, the field is used to represent the attribute of the object, and the field value stores the attribute value.
For example: store the car object with ID 2.
If the Hash contains a few fields, then this type of data will only take up very little disk space. Each Hash can store 4294967295 key-value pairs.

1、 HSET/HGET/HDEL/HEXISTS/HLEN/HSETNX

redis 127.0.0.1:6379> hset myhash field1 "zhang"   #给键值为myhash的键设置字段为field1,值为zhang。
(integer) 1
redis 127.0.0.1:6379> hget myhash field1     #获取键值为myhash,字段为field1的值。
"zhang"
redis 127.0.0.1:6379> hget myhash field2     #myhash键中不存在field2字段,因此返回nil.
(nil)
redis 127.0.0.1:6379> hset myhash field2 "san"  #给myhash添加一个新的字段field2,其值为san。
(integer) 1
redis 127.0.0.1:6379> hlen myhash             #hlen命令获取myhash键的字段数量。
(integer) 2
redis 127.0.0.1:6379> hexists myhash field1   #判断myhash键中是否存在字段名为field1的字段,由于存在,返回值为1。
(integer) 1
redis 127.0.0.1:6379> hdel myhash field1      #删除myhash键中字段名为field1的字段,删除成功返回1。
(integer) 1
redis 127 .0.0.1:6379> hdel myhash field1    #再次删除myhash键中字段名为field1的字段,由于上一条命令已经将其删除,因为没有删除,返回0
(integer) 0
redis 127 .0.0.1:6379> hexists myhash field1  #判断myhash键中是否存在field1字段,由于上一条命令已经将其删除,因为返回0。
(integer) 0
redis 127.0.0.1:6379> hsetnx myhash field1 zhang  #通过hsetnx命令给myhash添加新字段field1,其值为zhang,因为该字段已经被删除,所以该命令添加成功并返回1
(integer) 1
redis 127.0.0.1:6379> hsetnx myhash field1 zhang  #由于myhash的field1字段已经通过上一条命令添加成功,因为本条命令不做任何操作后返回0。
(integer) 0

2、HINCRBY

redis 127.0.0.1:6379> del myhash     #删除该键,便于后面示例的测试。
(integer) 1
redis 127.0.0.1:6379> hset myhash field 5  #准备测试数据,该myhash的field字段设定值5。
(integer) 1
redis 127.0.0.1:6379> hincrby myhash field 1  #hincrby命令给myhash的field字段的值加1,返回加后的结果。
(integer) 6
redis 127.0.0.1:6379> hincrby myhash field -1  #hincrby命令给myhash的field字段的值加-1,返回加后的结果。
(integer) 5
redis 127.0.0.1:6379> hincrby myhash field -10  #hincrby命令给myhash的field字段的值加-10,返回加后的结果。
(integer) -5

3 、 HGETALL / HKEYS / HVALS / HMGET / HMSET

redis 127.0.0.1:6379> del myhash   #删除该键,便于后面示例测试。
(integer) 1
redis 127.0.0.1:6379> hmset myhash field1 "hello" field2 "world"
#hmset命令为该键myhash,一次性设置多个字段,分别是field1="hello",field2="world"。
OK
redis 127.0.0.1:6379> hmget myhash field1 field2 field3
#hmget命令获取myhash键的多个字段,其中field3并不存在,因为在返回结果中与该字段对应的值为nil。
1) "hello"
2) "world"
3) (nil)
redis 127.0.0.1:6379> hgetall myhash   #hgetall命令返回myhash键的所有字段及其值,从结果中可以看出,他们是逐对列出的。
1) "field1"
2) "hello"
3) "field2"
4) "world"
redis 127.0.0.1:6379> hkeys myhash    #hkeys命令仅获取myhash键中所有字段的名字。
1) "field1"
2) "field2"
redis 127.0.0.1:6379> hvals myhash    #hvals命令仅获取myhash键中所有字段的值。
1) "hello"
2) "world" 

Four, set data type (unordered collection)

Overview: Unordered collection, the element type is string type, the element is unique, and no duplicate members are allowed. Union, intersection and difference operations can be performed between multiple collection types

Application scope:
1. You can use the Set data type of Redis to track some unique data, such as the unique IP address information for accessing a certain blog. For this scenario, we only need to store the visitor's IP in Redis every time we visit the blog, and the Set data type will automatically ensure the uniqueness of the IP address.
2. Make full use of the convenient and efficient features of the Set type of server aggregation operation, which can be used to maintain the association relationship between data objects. For example, all customer IDs who purchased a certain electronic device are stored in a specified Set, and the customer ID of another electronic product is stored in another Set. If we want to obtain which customers have purchased this at the same time When there are two kinds of commodities, the intersections command of Set can give full play to its advantages of convenience and efficiency.

1 、 SADD / SMEMBERS / SCARD / SISMEMBER

redis 127.0.0.1:6379> sadd myset a b c   #插入测试数据,由于该键myset之前并不存在,因此参数中的三个成员都被正常插入。
(integer) 3
redis 127.0.0.1:6379> sadd myset a d e   #由于参数中的a在myset中已经存在,因此本次操作仅仅插入了d和e两个新成员。
(integer) 2
redis 127.0.0.1:6379> sismember myset a   #判断a是否已经存在,返回值为1表示存在。
(integer) 1
redis 127.0.0.1:6379> sismember myset f   #判断f是否已经存在,返回值为0表示不存在。
(integer) 0
redis 127.0.0.1:6379> smembers myset     #通过smembers命令查看插入的结果,从结果可以看出,输出的顺序和插入顺序无关。
1) "c"
2) "b"
3) "a"
4) "d"
5) "e"
redis 127.0.0.1:6379> scard myset        #获取Set集合中元素的数量
(integer) 5

2、SPOP/SREM/ SRANDMEMBER/ SMOVE

redis 127.0.0.1:6379> del myset            #删除该键,便于后而的测试。
(integer) 1
redis 127.0.0.1:6379> sadd myset a b c d   #为后面的示例准备测试数据。
(integer) 4
redis 127.0.0.1:6379> smembers myset       #查看Set中成员的位置。
1) "d"
2) "a"
3) "b"
4) "c"
redis 127.0.0.1: 6379> srandmember myset   #从结果可以看出,该命令确实是随机的返回了某一成员
"c"
redis 127.0.0.1:6379> spop myset           #随机的移除并返回Set中的某一成员。
"d"
redis 127.0.0.1:6379> smembers myset       #查看移出后set的成员信息。
1) "a"
2) "b"
3) "c"
redis 127.0.0.1:6379> srem myset a d f     #从Set中移出a、d和f三个成员,其中f并不存在,因此只有a和d两个成员被移出,返回为2。
(integer) 1
redis 127.0.0.1:6379> smembers myset      #查看移出后的输出结果。
1) "b"
2) "c"
redis 127.0.0.1:6379> sadd myset a b      #为后面的smove命令准备数据。
(integer) 1
redis 127.0.0.1:6379> sadd myset2 c d
(integer) 2
redis 127.0.0.1:6379> smove myset myset2 a    #将a从myset移到myset2,从结果可以看出移动成功。
(integer) 1
redis 127.0.0.1:6379> smove myset myset2 a     #再次将a从myset移到myset2,由于此时a已经不是myset的成员了,因此移动失败并返回0。
(integer) 0
redis 127.0.0.1:6379> smembers myset         #分别查看myset和myset2的成员,确认移动是否真的成功。
1) "b"
2) "c"
redis 127.0.0.1:6379> smembers myset2
1) "a"
2) "d"
3) "c"

Five, Sorted Set data type (zset, ordered set)

Overview:
a. Ordered collection, the element type is Sting, the element is unique and cannot be repeated.
b. Each element will be associated with a double type score (representing weight), which can be sorted by the size of the weight, and the score of the elements can be the same.

Application scope:

1. It can be used for the scoreboard of a large-scale online game. Whenever the player's score changes, you can execute the ZADD command to update the player's score, and then use the ZRANGE command to obtain the user information of the TOP10 points. Of course, we can also use the ZRANK command to get the player's ranking information through username. Finally, we will combine the ZRANGE and ZRANK commands to quickly obtain the information of other users whose points are similar to a certain player.

2. The Sorted-Set type can also be used to build index data.

1、ZADD/ ZCARD/ ZCOUNT / ZREM/ ZINCRBY/ ZSCORE/ ZRANGE/ ZRANK

redis 127.0.0.1:6379> zadd myzset 1 "one"    #添加一个分数为1的成员。
(integer) 1
redis 127.0.0.1:6379> zadd myzset 2 "two" 3 "three"   #添加两个分数分别是2和3的两个成员。
(integer) 2
redis 127.0.0.1:6379> zrange myzset 0 -1 WITHSCORES   #0表示第一个成员,-1表示最后一个成员。WITHSCORES选 项表示返回的结果中包含每个成员及其分数,否则只返回成员。
1) "one"
2) "1"
3) "two"
4) "2"
5) "three"
6) "3"
redis 127.0.0.1:6379> zrank myzset one   #获取成员one在Sorted-Set中的位置索引值。0表示第一个位置。
(integer) 0
redis 127.0.0.1:6379> zrank myzset four   #成员four并不存在,因此返回nil。
(nil)
redis 127.0.0.1:6379> zcard myzset        #获取myzset键中成员的数量。
(integer) 3
redis 127.0.0.1:6379> zcount myzset 1 2    #zcount key min max,分数满足表达式1 <= score <= 2的成员的数量。
(integer) 2
redis 127.0.0.1:6379> zrem myzset one two   #删除成员one和two,返回实际删除成员的数量
(integer) 2
redis 127.0.0.1:6379> zcard myzset           #查看是否删除成功。
(integer) 1
redis 127.0.0.1:6379> zscore myzset three    #获取成员three的分数。返回值是字符串形式。
"3"
redis 127.0.0.1:6379> zscore myzset two      #由于成员two已经被删除,所以该命令返回nil。
(nil)
redis 127 .0.0.1:6379> zincrby myzset 2 one   #成员one不存在,zincrby命令将添加该成员并假设其初始分数为0,将成员one的分数增加2,并返回该成员更新后的分数。
"2"
redis 127.0.0.1:6379> zincrby myzset -1 one    #将成员one的分数增加-1,并返回该成员更新后的分数。
"1"
redis 127.0.0.1:6379> zrange myzset 0 -1 WITHSCORES   #查看在更新了成员的分数后是否正确。
1) "one"
2) "1'
3) "three"
4) "3"

2、ZRANGEBYSCORE/ ZREMRANGEBYRANK/ ZREMRANGEBYSCORE

redis 127.0.0.1:6379> del myzset
(integer) 1
redis 127.0.0.1:6379> zadd myzset 1 one 2 two 3 three 4 four
(integer) 4
redis 127.0.0.1:6379> zrangebyscore myzset 1 2     #zrangebyscore key min max,获取分数满足表达式1 <= score <= 2的成员。
1) "one"
2) "two"
redis 127.0.0.1:6379> zrangebyscore myzset (1 2    #获取分数满足表达式1 < score <= 2的成员。
1) "two"
redis 127.0.0.1:6379> zrangebyscore myzset -inf +inf limit 2 3   
 #-inf表示第一个成员(位置索引值最低的,即0),+inf表示最后一个成员(位置索引值最高的),limit后面的参数用于限制返回成员的值,2表示从位置索引等于2的成员开始,取后而3个成员。
1) "three"
2) "four"
redis 127.0.0.1:6379> zrangebyscore myzset 0 4 limit 2 3
1) "three"
2) "four"
redis 127.0.0.1:6379> zremrangebyscore myzset 1 2    #删除分数满足表达式1 <= score <= 2的成员,并返回实际删除的数量。
(integer) 2
redis 127.0.0.1:6379> zrange myzset 0 -1       #查看一下.上面的删除是否成功。
1) "three"
2) ”four"
redis 127.0.0.1:6379> zremrangebyrank myzset 0 1    #删除位置索引满足表达式0 <= rank <= 1的成员。
(integer) 2
redis 127 .0.0.1:6379> zcard myzset     #查看上--条命令是否删除成功。
(integer) 0

3 、 ZREVRANGE / ZREVRANGEBYSCORE / ZREVRANK

redis 127.0.0.1:6379> del myzset     #为后面的示例准备测试数据。
(integer) 1
redis 127.0.0.1:6379> zadd myzset 1 one 2 two 3 three 4 four
(integer) 4
redis 127.0.0.1:6379> zrevrange myzset 0 -1 WITHSCORES     #以位置索引从高到低的方式获取并返回此区间内的成员。
1) "four"
2) "4"
3) "three"
4) "3"
5) "two"
6) "2"
7) "one"
8) "1"
redis 127.0.0.1:6379> zrevrange myzset 1 3     #由于是从高到低的排序,所以位置等于0的是four,1是three,并以此类推。
1) "three"
2) "two"
3) "one"
redis 127.0.0.1:6379> zrevrank myzset one    #由于是从高到低的排序,所以one的位置是3。
(integer) 3
redis 127.0.0.1:6379> zrevrank myzset four    #由于是从高到低的排序,所以four的位置是0。
(integer) 0
redis 127.0.0.1:6379> zrevrangebyscore myzset 3 0    # zrevrangebyscore key max min,获取分数满足表达式3 >= score >= 0的成员,并以从高到底的顺序输出。
1) "three"
2) "two"
3) "one"
redis 127.0.0.1:6379> zrevrangebyscore myzset 4 0 limit 1 2    #zrevrangebyscore命令支持limit选项,其含义等同于zrangebyscore中的该选项,只是在计算位置时按照相反的顺序计算和获取。
1) "three"
2) "two"
192.168.80.10:6379> zrevrangebyscore myzset +inf -inf limit 1 3
1) "three"
2) "two"
3) "one"

Guess you like

Origin blog.csdn.net/qq_35456705/article/details/114579823