![]() It's also possible to remove ranges of elements. Infinity and 1950 (both extremes are included). ![]() We asked Redis to return all the elements with a score between negative Use the ZRANGEBYSCORE command to do it: > zrangebyscore hackers -inf 1950 Let's get all the individuals that were born up to 1950 inclusive. It is possible to return scores as well, using the WITHSCORES argument: > zrange hackers 0 -1 withscores Use ZREVRANGE instead of ZRANGE: > zrevrange hackers 0 -1 What if I want to order them the opposite way, youngest to oldest? Here just as it does in the case of the LRANGE command). Note: 0 and -1 means from element index 0 to the last element (-1 works Good, but when we ask for sorted elements Redis does not have to do any work atĪll, it's already all sorted: > zrange hackers 0 -1 Implementation note: Sorted sets are implemented via aĭual-ported data structure containing both a skip list and a hash table, soĮvery time we add an element Redis performs an O(log(N)) operation. With sorted sets it is trivial to return a list of hackers sorted by theirīirth year because actually they are already sorted. Pairs, even if this is not used in the example above. ZADD is also variadic, so you are free to specify multiple score-value (placed before the element to be added) which is the score. > zadd hackers 1940 "Alan Kay"Īs you can see ZADD is similar to SADD, but takes one additional argument Sorted set elements, with their year of birth as "score". Let's start with a simple example, adding a few selected hackers names as B and A strings can't be equal since sorted sets only have unique elements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |