Introduction to the

Add score on the basis of set to sort according to score

Create queries and remove

The title
zadd Adds one or more member elements and their score values to the ordered set key. If a member is already a member of an ordered set, update the score value for that member and reinsert the member element to ensure that the member is in the correct position. Score values can be integer values or double – precision floating – point numbers. If the key does not exist, an empty ordered set is created and the ZADD operation is performed. An error is returned when key exists but is not of an ordered set type.
zrange Returns a member of the ordered set key within the specified range. The positions of members are sorted by increasing score (from small to large).details
zrevrange Returns a member of the ordered set key within the specified range. Members are placed in descending order of score (from highest to lowest). Members with the same score value are arranged in reverse Lexicographical order. Apart from the fact that members are arranged in descending order of score, other aspects of the ZREVRANGE command andZRANGE key start stop [WITHSCORES]Same order.
zrem Removes one or more members of the ordered set key. Nonexistent members are ignored. An error is returned when key exists but is not of an ordered set type.
zcard Returns the cardinality of the ordered set key.
127.0.0.1:6379> zadd rank 10 baidu.com 5 bing.com 15 google.com  Key score member [score member]
(integer) 3 127.0.0.1:6379> zrange rank 0-1# query the ascending order
1) "bing.com"
2) "baidu.com"
3) "google.com"127.0.0.1:6379> zrange rank 0-1 withscoresQuery score from small to large withscores
1) "bing.com"
2) "5"
3) "baidu.com"
4) "10"
5) "google.com"
6) "15"127.0.0.1:6379> zrevrange rank 0-1 withscores# in reverse order from largest to smallest
1) "google.com"
2) "15"
3) "baidu.com"
4) "10"
5) "bing.com"
6) "5"127.0.0.1:6379 > zrem rank baidu.com# remove
(integer) 1 127.0.0.1:6379> zrange rank 0-1 1)"bing.com"
2) "google.com"127.0.0.1:6379 > zcard rankHow many elements does zset have
(integer2)Copy the code
The title
zcount Returns all members of the ordered set key whose score is between min and Max (including the members whose score is equal to min or Max by default)The number of.
127.0.0.1:6379> zadd rank2 40 baidu.com 46 bing.com 55 google.com 30 baidu.com (integer) 4 127.0.0.1:6379> zrange rank2 0-1 withscores 1)"bilibili.com"
2) "30"
3) "baidu.com"
4) "40"
5) "bing.com"
6) "46"
7) "google.com"
8) "55"
127.0.0.1:6379> zcount rank2 40 55   Select * from score where score = 40,50
(integer) 3

Copy the code