The design of an ordered set (Sorted set) in Redis to determine the existence of a member of a key

Source: Internet
Author: User
Tags redis

In general, Redis's Zset provides a wealth of functionality that can form many applications.

In Redis, there are many features that are available.

Ordered set (Sorted set) zadd zrem zcard zcount zscore zincrby zrange zrevrange zrangebyscore zrevrangebyscore ZRANK ZREVRANK ZREMR Angebyrank Zremrangebyscore Zinterstore Zunionstore

However, there is currently no function to judge whether a key in the Zset has a specified member, and this is what is currently seen on the Web to write the corresponding code. And this work has found a clever and alternative approach. That is, the Zrank method is used to determine whether there is. The function interface is defined as follows:

Zrank Key Member

Returns the rank of the member member in the ordered set key. Where ordered set members are arranged in ascending order of score values (from small to large).

The ranking is based on 0, meaning that the member with the lowest score value is ranked at 0.

Use the Zrevrank command to get the ranking of members in descending order of score values (from large to small).


It can be considered that when this ranking does not exist, the member does not exist. The test is as follows:



Using the program to design, the results are as follows:



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.