
This is the first time that you’ve seen a few of these commands. ZUNIONSTORE dest-key key-count key ] - Performs a SET-like union of the provided ZSETs ZINTERSTORE dest-key key-count key ] - Performs a SET-like intersection of the provided ZSETs ZREMRANGEBYSCORE key-name min max - Removes the items from the ZSET with scores between min and max ZREMRANGEBYRANK key-name start stop - Removes the items from the ZSET with ranks between start and stop ZREVRANGEBYSCORE key max min - Fetches the members in reverse order between min and max ZRANGEBYSCORE key min max - Fetches the members between min and max ZREVRANGE key-name start stop - Fetches the given members from the ZSET by rank, with members in reverse order ZREVRANK key-name member - Returns the position of the member in the ZSET, with members ordered in reverse Table 3.10 Commands for fetching and deleting ranges of data from ZSETs and offering SET-like intersections Command Table 3.10 shows several more ZSET commands in Redis that you’ll find useful. The ZCOUNT command is a little different than the others, primarily meant to let you discover the number of values whose scores are between the provided minimum and maximum scores.

You’ll likely remember our use of ZADD, ZREM, ZINCRBY, ZSCORE, and ZRANGE from chapters 1 and 2, so their semantics should come as no surprise. Listing 3.9 A sample interaction showing some common ZSET commands in Redisįor debugging, we usually fetch the entire ZSET with this ZRANGE call, but real use cases will usually fetch items a relatively small group at a time. Let’s quickly revisit the use of some of our commands. We’ve used some of these commands in chapters 1 and 2, so they should already be familiar to you. ZRANGE key-name start stop - Returns the members and optionally the scores for the members with ranks between start and stop ZSCORE key-name member - Returns the score of the member in the ZSET ZRANK key-name member - Returns the position of the given member in the ZSET ZCOUNT key-name min max - Returns the number of members with scores between the provided minimum and maximum ZINCRBY key-name increment member - Increments the member in the ZSET ZCARD key-name - Returns the number of members in the ZSET ZREM key-name member - Removes the members from the ZSET, returning the number of members that were removed

ZADD key-name score member - Adds members with the given scores to the ZSET Table 3.9 Some common ZSET commands Command Let’s look at some commonly used ZSET commands in table 3.9. When finished with this section, you’ll have a much clearer understanding about how ZSETs work, which will help you to better understand what we did with them in chapter 1, and how we’ll use them in chapters 5, 6, and 7.
LUA TABLE INSERT SORTED INMEMORY HOW TO
You’ll learn how to add and update items in ZSETs, as well as how to use the ZSET intersection and union commands. In this section, we’ll talk about commands that operate on ZSETs. In chapter 1, we showed a brief example that used ZSETs as a way of sorting submitted articles based on time and how many up-votes they had received, and in chapter 2, we had an example that used ZSETs as a way of handling the expiration of old cookies. These mappings allow us to manipulate the numeric scores, 2 and fetch and scan over both members and scores based on the sorted order of the scores. ZSETs offer the ability to store a mapping of members to scores (similar to the keys and values of HASHes).
