Upstash Documentation

XADD

Appends one or more new entries to a stream.
2 min read

Arguments#

keystringrequired#

The key to of the stream.

idstring | *required#

The stream entry ID. Supports multiple formats:

  • *: Fully automatic ID generation (both timestamp and sequence)
  • <ms>-<seq>: Explicit ID (e.g., "1526919030474-55")
  • <ms>-*: Auto-generate sequence number for the given millisecond timestamp (Redis 8+)
entriesRecord<string, unknown>required#

Key-value data to be appended to the stream.

optionsobject#
Show properties
nomkStreamboolean#

Prevent creating the stream if it does not exist.

trimobject#

Trim options for the stream.

Show trim
type'MAXLEN' | 'MINID'required#

The trim strategy:

  • MAXLEN: Trim based on the maximum number of entries
  • MINID: Trim based on the minimum ID
thresholdnumber | stringrequired#

The threshold value for trimming:

  • For MAXLEN: The maximum number of entries to keep (number)
  • For MINID: The minimum ID to keep (string)
comparison'~' | '='required#

The comparison operator:

  • ~: Approximate trimming (more efficient)
  • =: Exact trimming
limitnumber#

Limit how many entries will be trimmed at most

Response#

ID Format Details#

Automatic ID (*)#

Fully automatic - Redis generates both the millisecond timestamp and sequence number.

Explicit ID (<ms>-<seq>)#

You provide both the millisecond timestamp and sequence number. Example: "1526919030474-55"

Auto Sequence (<ms>-*) - Redis 8+#

You provide the millisecond timestamp, Redis automatically generates the sequence number. This is useful when you need precise control over the timestamp but want Redis to handle sequence numbering.

Benefits of Auto Sequence:

  • Precise timestamp control for time-sensitive data
  • Automatic sequence management prevents conflicts
  • Multiple entries can share the same millisecond with different sequences
  • Ideal for batch operations with consistent timestamps