Redis Set frequently used commands and ZSet

Redis Set frequently used commands and ZSet

Set

1. the SADD: a plurality of elements added to the collection
127.0.0.1:6379> sadd goodfood "potato" "tomato" "apple"
(integer) 3
2. the SMOVE command: move to another collection element set
smove source destination member
3. SUNIONSTORE command: save more than a collection of elements to the new collection
127.0.0.1:6379> sunionstore foods goodfood
(integer) 3
4. SISMEMBER command: determining whether an element in the collection
5. The SCARD command: Get the number of elements in the set
6. SMEMBERS command: Get all elements in the collection
7. The SRANDMEMBER command: Get a random element in the set
8. The SUNION command: Get all the elements in the plurality of sets
127.0.0.1:6379> sunionstore foods goodfood
(integer) 3
127.0.0.1:6379> sismember foods "apple"
(integer) 1
127.0.0.1:6379> scard foods
(integer) 3
127.0.0.1:6379> smembers foods
1) "apple"
2) "tomato"
3) "potato"
127.0.0.1:6379> srandmember foods
"apple"
127.0.0.1:6379> srandmember foods 2
1) "apple"
2) "potato"
127.0.0.1:6379> sunion foods goodfood
1) "apple"
2) "tomato"
3) "potato"
9. The sdiff command: acquiring a plurality of sets of elements of the set difference
127.0.0.1:6379> sdiff foods goodfood
(empty list or set)
10. The SDIFFSTORE command: Get the number of the plurality of elements of the set difference sets (returning a new collection difffood)
127.0.0.1:6379> sdiffstore difffood foods goodfood
(integer) 0
11. SINTER command: get the intersection of multiple sets of elements
127.0.0.1:6379> sinter foods goodfood
1) "apple"
2) "tomato"
3) "potato"
12. The SINTERSTORE command: Get the number of elements of the plurality of set intersection (returning a new collection newfood)
127.0.0.1:6379> sinterstore newfood foods goodfood
(integer) 3
13. The SPOP command: random delete elements in the collection
14. The SREM command: delete multiple elements in the collection
127.0.0.1:6379> spop foods
"potato"
127.0.0.1:6379> srem foods "apple"
(integer) 1

token

1. ZADD: adding to an ordered set a plurality of elements
127.0.0.1:6379> zadd city:gdp 95 "beijing" 99.5 "shanghai" 98 "guangzhou"
(integer) 3
2. ZINCRBY command: add incremental value as a fraction
127.0.0.1:6379> zincrby city:gdp 3 "beijing"
"98"
3. ZCARD command: Get the number of elements in an ordered set
4. ZCOUNT command: Get the number of elements in the score range
127.0.0.1:6379> zcard city:gdp
(integer) 3
127.0.0.1:6379> zcount city:gdp 99 100
(integer) 1
5. The ZLEXCOUNT command: Get the number of elements within the specified range

ZLEXCOUNT command obtains the number of elements in the ordered set of key intermediary min and max ranges, the ordered set of score values ​​of all elements of the key are equal.

Max and min parameters are an interval, the interval is generally used "(" or "[", where, "(" open interval represented, "(" value will not be included in the range; "[" indicates the closed interval , "[" the specified value will be included in the scope of the addition, the special values ​​+ and - have a special meaning in the parameters min and max, where + indicates positive infinity, - representing negative infinity we identical to an element scores the ordered set of transmission command ZLEXCOUNT <zset> - +, will return all elements of the ordered set.

6. The Z Range The command: Get element within the specified range (in ascending order)
127.0.0.1:6379> zrange city:gdp 0 -1
1) "beijing"
2) "guangzhou"
3) "shanghai"
7. The ZREVRANGE command: Get element within the specified range (descending)
8. The ZSCORE command: Get value of the element points
127.0.0.1:6379> zscore city:gdp "beijing"
"98"
9. The ZRANGEBYLEX command: Get set within a specified range of elements

ZRANGEBYLEX key command returns an ordered set, the elements interposed between elements of the score value min and max, the ordered set of all key elements have the same score value, sorted according to the lexicographic order. If a different ordered set of elements corresponding to the key value score, then after this command is executed, the result returned is not specified (unspecified).

Alternatively LIMIT offset count parameter for obtaining matching elements in the specified range. At this point, you need to pay attention to, if the value of the offset parameter is very large, then the command before returning the results, you need to traverse to the offset location specified.

Max and min parameters are an interval, the interval is generally used "(" or "[", where, "(" open interval represented, "(" value will not be included in the range; "[" indicates the closed interval , "[" the specified value will be included in the scope of the addition, the special values ​​+ and - have a special meaning in the parameters min and max, where + indicates positive infinity, - representing negative infinity we identical to an element scores the ordered set of transmission command ZRANGEBYLEX <zset> - +, will return all elements of the ordered set.

10. The ZRANGEBYSCORE command: Get the specified element in the score range
127.0.0.1:6379> ZRANGEBYSCORE  city:gdp 0 100
1) "beijing"
2) "guangzhou"
3) "shanghai"
11. ZREVRANGEBYSCORE command: Get all the elements within the specified range

RANGEBYSCORE command returns an ordered set key, all the score value element interposed between min and max (comprising equal to min and max),. Ordered set of key elements in accordance with the score value ascending order. When you do not know the exact values ​​of the parameters min and max may be used to represent -inf min values, + inf used to represent the value of max. By default, min and max interval is closed interval (greater than or equal to or less) may be added "(" symbol in front of the optional parameters used open interval (less than or greater than).

When the elements having the same score values, ordered set of items are sorted according to the lexicographic order.

Use WITHSCORES option to return a score value of the element.

Alternatively LIMIT offset count parameter for obtaining matching elements in the specified range. If the value of the offset parameter is very large, then the command before returning the results, you need to traverse to the offset location specified.

12. ZRANK command: Get rank ordered collection of elements
13. The ZREVRANK command: Get reverse Ranked ordered collection of elements
127.0.0.1:6379> zrank city:gdp "shanghai"
(integer) 2
14. The ZINTERSTORE command: save the intersection of the plurality of ordered sets
15. The ZUNIONSTORE command: save multiple ordered collection of union
16. The ZREM command: Delete multiple elements of an ordered set
127.0.0.1:6379> zrem city:gdp "shanghai"
(integer) 1
17. The ZREMRANGEBYLEX command: Remove ordered collection of elements within the specified range
18. The ZREMRANGEBYRANK command: Remove ordered collection of elements within the specified position range
19. The ZREMRANGEBYSCORE command: Remove ordered collection of elements within a specified score range

Guess you like

Origin www.cnblogs.com/undefined22/p/12566219.html