Redis (2.8.3) Command Learning-Sorted sets

Source: Internet
Author: User

Zadd key score member [score member ...]

ADD one or more members to a sorted set, or update its score if it already exists

127.0.0.1:6379> zadd foo 1 One (integer) 1127.0.0.1:6379> zadd foo 2 (integer) 1127.0.0.1:6379> zadd foo 3 thre E (integer) 1127.0.0.1:6379> zrange foo 0-11) "one" 2) "3" "three"

More:http://redis.io/commands/zadd, http://www.redis.cn/commands/zadd.html

Zcard Key

Get the number of members in a sorted set

127.0.0.1:6379> zrange foo 0-11) "one" 2) "3" "three" 127.0.0.1:6379> zcard foo (integer) 3127.0.0.1:6379> ZRA NGE None 0-1 (empty list or set) 127.0.0.1:6379> zcard None (integer) 0

More:http://redis.io/commands/zcard, http://www.redis.cn/commands/zcount.html

Zcount Key min Max

Count the members in a sorted set with scores within the given values

127.0.0.1:6379> zadd foo, A, B, D (integer) 4127.0.0.1:6379> zcount foo (integer) 2127.0.0.1:6379> Zcount foo (integer) 1127.0.0.1:6379> zcount foo (integer) 1

More:http://redis.io/commands/zcount, http://www.redis.cn/commands/zcount.html

Zincrby Key Increment member

Increment the score of a member in a sorted set

127.0.0.1:6379> zadd Foo 1 a 2 b (integer) 2127.0.0.1:6379> zincrby foo 2 A "3" 127.0.0.1:6379> zrange foo 0-1 with SCORES1) "B" 2) "2" 3) "a" 4) "3"

More:http://redis.io/commands/zincrby, http://www.redis.cn/commands/zincrby.html

Zinterstore destination Numkeys key [key ...] [WEIGHTS weight [weight ...] [AGGREGATE sum| min| MAX]

Intersect multiple sorted sets and store the resulting sorted set in a new key

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C (integer) 3127.0.0.1:6379> zadd bar 1 B 2 c 3 D (integer) 3127.0.0.1:6379> ZIN Terstore result 2 foo bar (integer) 2127.0.0.1:6379> zrange result 0-1 WITHSCORES1) "B" 2) "3" 3) "C" 4) "5" 127.0.0.1:6379 > Zinterstore result 2 foo bar AGGREGATE MAX (integer) 2127.0.0.1:6379> zrange result 0-1 WITHSCORES1) "B" 2) "2" 3) " C "4)" 3 "

More:http://redis.io/commands/zinterstore, http://www.redis.cn/commands/zinterstore.html

Zlexcount Key min Max

Count the number of members in a sorted set between a given lexicographical range

More:http://redis.io/commands/zlexcount

Zrange key start stop [Withscores]

Return a range of members in a sorted set, by index

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 4 D (integer) 4127.0.0.1:6379> zrange foo 0-11) "a" 2) "B" 3) "C" 4) "D" 127.0.0.1: 6379> zrange foo 1 2 WITHSCORES1) "B" 2) "2" 3) "C" 4) "3"

More:http://redis.io/commands/zrange, http://www.redis.cn/commands/zrange.html

Zrangebylex key min Max [LIMIT offset Count]

Return a range of members in a sorted set, by lexicographical range

More:http://redis.io/commands/zrangebylex

Zrangebyscore key min Max [withscores] [LIMIT offset Count]

Return a range of members in a sorted set, by score

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 4 D 5 E (integer) 5127.0.0.1:6379> zrangebyscore foo-inf +inf1) "a" 2) "B" 3) "C"  4) "D" 5) "E" 127.0.0.1:6379> zrangebyscore foo-inf +inf LIMIT 0) "a" 2) "B" 3) "C" 127.0.0.1:6379> zrangebyscore foo  1 3 WITHSCORES1) "a" 2) "1" 3) "B" 4) "2" 5) "C" 6) "3" 127.0.0.1:6379> zrangebyscore foo (1) "B" 2) "C" 127.0.0.1:6379> Zrangebyscore Foo 1 (+) "a" 2) "B"

More:http://redis.io/commands/zremrangebyscore, http://www.redis.cn/commands/zrangebyscore.html

Zrank Key Member
Determine the index of a member in a sorted set

127.0.0.1:6379> zadd Foo 1 a 2 B 2 c 3 D (integer) 4127.0.0.1:6379> zrank foo A (integer) 0127.0.0.1:6379> zrank fo o B (integer) 1127.0.0.1:6379> zrank foo C (integer) 2127.0.0.1:6379> zrank foo E (nil)

More:http://redis.io/commands/zrank, http://www.redis.cn/commands/zrank.html

Zrem key member [member ...]

Remove one or more members from a sorted set

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 4 D (integer) 4127.0.0.1:6379> zrem foo b d (integer) 2127.0.0.1:6379> zrange Foo 0-11) "a" 2) "C" 127.0.0.1:6379> zrem foo E (integer) 0

More:http://redis.io/commands/zrem, http://www.redis.cn/commands/zrem.html

Zremrangebylex Key min Max

Remove all members in a sorted set between the given lexicographical range

More:http://redis.io/commands/zremrangebylex

Zremrangebyrank Key Start stop

Remove all members in a sorted set within the given indexes

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 4 D 5 E (integer) 5127.0.0.1:6379> zremrangebyrank foo 0 2 (integer) 3127.0.0.1:6 379> zrange foo 0-1 WITHSCORES1) "D" 2) "4" 3) "E" 4) "5"

More:http://redis.io/commands/zremrangebyrank, http://www.redis.cn/commands/zremrangebyrank.html

Zremrangebyscore Key min Max

Remove all members in a sorted set within the given scores

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 4 D 5 E (integer) 5127.0.0.1:6379> zremrangebyscore foo 3 5 (integer) 3127.0.0.1: 6379> zrange foo 0-1 WITHSCORES1) "a" 2) "1" 3) "B" 4) "2"

More:http://redis.io/commands/zremrangebyscore, http://www.redis.cn/commands/zremrangebyscore.html

Zrevrange key start stop [Withscores]

Return a range of members in a sorted set, by index, with scores ordered

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 4 D (integer) 4127.0.0.1:6379> zrevrange foo 0-11) "D" 2) "C" 3) "B" 4) "a" 127.0.0 .1:6379> zrevrange foo 0 1 WITHSCORES1) "D" 2) "4" 3) "C" 4) "3"

More:http://redis.io/commands/zrevrange, http://www.redis.cn/commands/zrevrange.html

Zrevrangebylex key Max min [LIMIT offset Count]

Return a range of members in a sorted set, by Lexicographical range, ordered from higher to lower strings.

More:http://redis.io/commands/zrevrangebylex

Zrevrangebyscore key Max min [withscores] [LIMIT offset Count]

Return a range of members in a sorted set, by score, with scores ordered from

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 4 D (integer) 4127.0.0.1:6379> zrevrangebyscore foo +inf-inf1) "D" 2) "C" 3) "B" 4 ) "A" 127.0.0.1:6379> zrevrangebyscore foo (3 1 WITHSCORES1) "B" 2) "2" 3) "a" 4) "1"

More:http://redis.io/commands/zrevrangebyscore, http://www.redis.cn/commands/zrevrangebyscore.html

Zrevrank Key Member

Determine the index of a member in a sorted set, with scores ordered from

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 2 D (integer) 4127.0.0.1:6379> zrevrank foo A (integer) 3127.0.0.1:6379> ZREVR ANK foo B (integer) 2127.0.0.1:6379> zrevrank foo C (integer) 0127.0.0.1:6379> zrevrank foo d (integer) 1

More:http://redis.io/commands/zrevrank, http://www.redis.cn/commands/zrevrank.html

Zscore Key Member

Get the score associated with the given member in a sorted set

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C 4 D (integer) 4127.0.0.1:6379> zscore foo B "2" 127.0.0.1:6379> zscore foo e (ni L

More:http://redis.io/commands/zscore, http://www.redis.cn/commands/zscore.html

Zunionstore destination Numkeys key [key ...] [WEIGHTS weight [weight ...] [AGGREGATE sum| min| MAX]

Add multiple sorted sets and store the resulting sorted set in a new key

127.0.0.1:6379> zadd Foo 1 a 2 B 3 C (integer) 3127.0.0.1:6379> zadd bar 1 B 2 c 3 D (integer) 3127.0.0.1:6379> ZUN  Ionstore result 2 foo bar (integer) 4127.0.0.1:6379> zrange result 0-1 WITHSCORES1) "a" 2) "1" 3) "B" 4) "3" 5) "D" 6) "3" 7) "C" 8) "5" 127.0.0.1:6379> zunionstore result 2 foo bar AGGREGATE MIN (integer) 4127.0.0.1:6379> zrange result 0-1 WI THSCORES1) "a" 2) "1" 3) "B" 4) "1" 5) "C" 6) "2" 7) "D" 8) "3"

More:http://redis.io/commands/zunionstore, http://www.redis.cn/commands/zunionstore.html

Zscan key cursor [MATCH pattern] [count Count]

Incrementally iterate sorted sets elements and associated scores

Redis (2.8.3) Command Learning-Sorted sets

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.