Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

XSETID

Last updated
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.

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).

Case RESP2 RESP3
Set Simple string OK Simple string OK

Error replies:

  • ERR no such key if the stream does not exist.
  • ERR The ID specified in XSETID is smaller than the target stream top item
  • ERR The entries_added specified in XSETID is smaller than the target stream length
  • ERR The ID specified in XSETID is smaller than the provided max_deleted_entry_id
  • ERR The ID specified in XSETID is smaller than current max_deleted_entry_id
  • ERR entries_added must be positive for a negative count.
  • ERR Invalid stream ID specified as stream command argument, ERR syntax error, or WRONGTYPE.
127.0.0.1:6379> XADD s 1700000000000-0 f v
"1700000000000-0"
127.0.0.1:6379> XSETID s 1800000000000-0
OK
127.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 item
127.0.0.1:6379> XSETID s 1600000000000-0
(error) ERR The ID specified in XSETID is smaller than the target stream top item

Same as Redis 7 and Valkey 8, including ENTRIESADDED and MAXDELETEDID.

XADD, XINFO STREAM, XGROUP SETID