// Specify millisecond timestamp, let Redis generate sequence numberconst ms = Date.now();const id1 = await redis.xadd("mystream", `${ms}-*`, { event: "login", user: "john" });console.log(id1); // e.g., "1769347235123-0"// Multiple entries with same ms but different sequence numbersconst id2 = await redis.xadd("mystream", `${ms}-*`, { event: "logout", user: "john" });console.log(id2); // e.g., "1769347235123-1"
// Use auto sequence for precise timestamp controlconst timestamp = 1634567890123;const result = await redis.xadd("events", `${timestamp}-*`, { type: "payment", amount: 100.00, currency: "USD"});// Redis generates the sequence number automatically
// Specify millisecond timestamp, let Redis generate sequence numberconst ms = Date.now();const id1 = await redis.xadd("mystream", `${ms}-*`, { event: "login", user: "john" });console.log(id1); // e.g., "1769347235123-0"// Multiple entries with same ms but different sequence numbersconst id2 = await redis.xadd("mystream", `${ms}-*`, { event: "logout", user: "john" });console.log(id2); // e.g., "1769347235123-1"
// Use auto sequence for precise timestamp controlconst timestamp = 1634567890123;const result = await redis.xadd("events", `${timestamp}-*`, { type: "payment", amount: 100.00, currency: "USD"});// Redis generates the sequence number automatically
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