Redis Commands
These are the commands we are using
HSET: stores multiple pieces of information under one key, like a mini dictionary. Think of it like a contact card.- The key is the person’s name.
- The fields are labels like “age” or “city”.
- The values are the actual age or city name.

Redis offers different data structures,
SETandHSETcommands belong to two different ones:SETworks with simple string values.HSETworks with hashes (think: mini‑key/value maps stored under one top-level key).
HGET: retrieves the value of a specific field from a hash stored at a given key in Redis.> HSET myhash field1 "foo" (integer) 1 > HGET myhash field1 "foo" > HGET myhash field2 (nil)-
ZADD: Add/update members in a sorted set with a score.> ZADD scores 90 "Alice" 85 "Bob" 95 "Charlie" (integer) 3- This creates a sorted set scores with:
Alicewith score 90.Bobwith score 85.Charliewith score 95.
- The set is sorted by score in ascending order:
Bob (85), Alice (90), Charlie (95).
> ZADD scores 192 "Alice" (integer) 0- Updates
Alice’s score to 192. Meaning alice will takeCharlie’s position.
- This creates a sorted set scores with:
ZRANGE: retrieves a specified range of elements from a sorted set.- It supports three types of range queries:
- By index (rank):
- Use 0-based indexes to get elements by position.
- Negative numbers count from the end.
> ZRANGE scores 0 -1 WITHSCORES 1) "Bob" 2) "85" 3) "Charlie" 4) "95" 5) "Alice" 6) "192" - By score:
- Use
BYSCOREto get elements within a score range. - You can use
-infand+inffor infinity, and (start,stop) for exclusive ranges. - The one used in our
OutboxService.
- Use
- By lexicographical order:
- Use
BYLEXto get elements within a string range. - Use
[for inclusive and(for exclusive ranges.
- Use
- By index (rank):
- Additional options:
REV: Reverses the order (highest to lowest score).LIMIT: Limits the number of results returned.WITHSCORES: Returns both values and their scores.
- It supports three types of range queries:
ZREM: Removes the specified members from the sorted set stored at key. Non existing members are ignored.> ZREM scores "Alice" (integer) 1 > ZRANGE scores 0 -1 WITHSCORES 1) "Bob" 2) "85" 3) "Charlie" 4) "95"SET: sets a key to a string value (used here withNXandPXfor locks).NXoption: set only if not exists.PXoption: sets the TTL for a key in milliseconds.> SET key value PX 5000
-
DEL: removes the specified keys. A key is ignored if it does not exist.> SET key1 "val1" "OK" > SET key2 "val2" "OK" > DEL key1 key2 key3 (integer) 2This command’s behavior varies in clustered Redis environments. In ioredis we have to delete them individually if they are in different slots.