XSETID
XSETID key last-id [ENTRIESADDED entries-added] [MAXDELETEDID max-deleted-id]
- Group
- Stream
- Complexity
- O(1)
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
XSETID sets the last generated ID of the stream at key. Entries added with
* then get IDs above it. Replication and migration tools use it to recreate
a stream exactly.
Options
Section titled “Options”| Option | Effect |
|---|---|
ENTRIESADDED entries-added |
Set the count of entries ever added to the stream (entries-added in XINFO STREAM). |
MAXDELETEDID max-deleted-id |
Set the highest ID ever deleted from the stream (max-deleted-entry-id in XINFO STREAM). |
The ID cannot be lower than the stream’s current last entry, ENTRIESADDED
cannot be lower than the stream’s length, and the ID cannot be lower than the
max deleted ID (the one given, or the current one).
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Set | Simple string OK |
Simple string OK |
Error replies:
ERR no such keyif the stream does not exist.ERR The ID specified in XSETID is smaller than the target stream top itemERR The entries_added specified in XSETID is smaller than the target stream lengthERR The ID specified in XSETID is smaller than the provided max_deleted_entry_idERR The ID specified in XSETID is smaller than current max_deleted_entry_idERR entries_added must be positivefor a negative count.ERR Invalid stream ID specified as stream command argument,ERR syntax error, orWRONGTYPE.
Examples
Section titled “Examples”127.0.0.1:6379> XADD s 1700000000000-0 f v"1700000000000-0"127.0.0.1:6379> XSETID s 1800000000000-0OK127.0.0.1:6379> XADD s 1750000000000-0 f v(error) ERR The ID specified in XADD is equal or smaller than the target stream top item127.0.0.1:6379> XSETID s 1600000000000-0(error) ERR The ID specified in XSETID is smaller than the target stream top itemCompatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8, including ENTRIESADDED and MAXDELETEDID.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.