Redis database Operations--zset ordered collection under LUnix

Source: Internet
Author: User
Tags redis lunix

Create: (The concept of a weight exists in an ordered set)

Zadd Zset 1 a 2 B 3 C 4 D 5 e 6 F 7 G#  output:#  1) "A"#  2) "B" c7>#  3) "C"#  4) "D"#  5) "E"#  6) "F"  #  7) "G"#  left weight, right element

View:

Zrange zset 0-1   #  index value, first and last

Reverse View:

Zrevrange zet 0-1#  output:#  1) "G"#  2) "F"#  3) "E" c8>#  4) "D"#  5) "C"#  6) "B"#  7) "a"

Delete:

Zrem Zset g (Element)

Element value view to view the corresponding index value:

Zrank Zset a    #  0 (index value)

Flashback view element value relative to index value;

Zrevrank Zset a    #  6   (' G ' has been removed before)

Number of Views:

Zcard zset   #  6

View weights:

# 1 (weight)zscore zset F  #  6 (weight)

Returns the elements of an ordered set of score (weights) at a given interval:

Zrangebyscore Zset 3 5 withscores  #  view elements with weights between 3 and 5 (closed interval)#  output:
1) "C"
2) "3"
3) "D"
4) "4"
5) "E"
6) "5"

Returns the number of score (weights) in a given interval in an ordered set:

# the number of elements with weights between 3 and 5 # Output: 3

Delete an indexed value in an ordered set of elements in a given interval:

Zremrangebyrank Zset 3 5  #  Delete an element with an index value from 3 to 5 (closed interval)#  return number 3   means D E F has been removed #< /c10> 's got a B-C left .

Delete the elements of a given interval in an ordered set of weights:

Zremrangebyscore zset 1 3  #  Remove weights from 1 to 3 (closed interval)#  Returns the number 3  means a B c has been deleted # now ordered set Zset is empty

Redis database Operations--zset ordered collection under LUnix

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.