Redis ordered set (sorted set)

Source: Internet
Author: User

Redis ordered set (sorted set)

A Redis ordered collection is a collection of elements of type string, as well as a collection, and does not allow duplicate members.

The difference is that each element is associated with a double-type fraction. Redis is a small-to-large ordering of the members in a collection by fractions.

The members of an ordered collection are unique, but fractions (score) can be duplicated.

The collection is implemented by a hash table, so the complexity of adding, deleting, and finding is O (1). The maximum number of members in the collection is 232-1 (4294967295, each of which can store 40多亿个 members).

Instance
Redis127.0.0.1:6379>Zadd Runoobkey1Redis(Integer) 1Redis127.0.0.1:6379>Zadd Runoobkey2Mongodb(Integer) 1Redis127.0.0.1:6379>Zadd Runoobkey3Mysql(Integer) 1Redis127.0.0.1:6379>Zadd Runoobkey3Mysql(Integer) 0Redis127.0.0.1:6379>Zadd Runoobkey4Mysql(Integer) 0Redis127.0.0.1:6379> Zrange runoobkey 0  10 Withscores1)   "Redis" 2  "1" 3)   "MongoDB" 4)   "2" 5)   "MySQL" 6)   "4"             

In the above example we add three values to the ordered set of Redis and associate the scores with the command Zadd .

Redis ordered Collection command

The following table lists the basic commands for the Redis ordered collection:

Serial Number Command and Description
1 Zadd key Score1 member1 [Score2 member2]
Add one or more members to an ordered collection, or update a fraction of an existing member
2 Zcard Key
Gets the number of members of an ordered collection
3 Zcount Key min Max
Calculates the number of members that specify interval fractions in an ordered set
4 Zincrby Key Increment member
The fractional plus increment of the specified member in an ordered collection increment
5 Zinterstore destination Numkeys key [key ...]
Computes the intersection of the given one or more ordered sets and stores the result set in the new ordered collection key
6 Zlexcount Key min Max
Calculates the number of members within a specified dictionary interval in an ordered collection
7 Zrange key start stop [Withscores]
Returns an ordered set of members within a specified range by an index interval
8 Zrangebylex key min Max [LIMIT offset Count]
Returning members of an ordered collection through a dictionary interval
9 Zrangebyscore key min Max [withscores] [LIMIT]
Returns the members of an ordered set within a specified interval by a fraction
10 Zrank Key Member
Returns the index of the specified member in an ordered collection
11 Zrem key member [member ...]
To remove one or more members from an ordered collection
12 Zremrangebylex Key min Max
Removes all members of a given dictionary interval in an ordered collection
13 Zremrangebyrank Key Start stop
Removes all members of a given rank range in an ordered collection
14 Zremrangebyscore Key min Max
Removes all members of a given fractional interval in an ordered collection
15 Zrevrange key start stop [Withscores]
Returns the members of the specified interval in an ordered set, through the index, the score from the high end
16 Zrevrangebyscore key Max min [Withscores]
Returns the members in the specified fractional interval in an ordered set, sorted from highest to lowest
17 Zrevrank Key Member
Returns the rank of the specified member in an ordered collection, sorted by the descending (large to small) fractional value of the ordered set member
18 Zscore Key Member
Returns the fractional value of a member in an ordered set
19 Zunionstore destination Numkeys key [key ...]
Calculates the set of a given one or more ordered sets and stores it in a new key
20 Zscan key cursor [MATCH pattern] [count Count]
Iterate elements in an ordered collection (including element members and element scores)

Redis ordered set (sorted set)

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.