Quantcast
Channel: How do I find the index of the first occurrence of a score in a sorted Redis set? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by sazzad for How do I find the index of the first occurrence of a score in a sorted Redis set?

$
0
0

You can use ZCOUNT from negative infinity to your specific score to find the index.

For example, in following sorted set:

> ZADD dewey 1 first 3 second 8 third 21 fourth 55 fifth
(integer) 5

To find the index of 21 (the fourth number):

> ZCOUNT dewey -inf (21
3

Just keep in mind that this is 0-based index.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>