1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-03 04:01:40 +03:00
Files
node-redis/examples/stream-producer.js
Simon Prickett 41f6b009d3 Add streams XREADGROUP and XACK example. (#1832)
* Removed stream delete command to allow consumer group example to work.

* Adds stream consumer group example.

* Adds stream consumer group example code.

* Update README.md

Co-authored-by: Leibale Eidelman <leibale1998@gmail.com>
2022-01-19 13:36:24 -05:00

28 lines
528 B
JavaScript

// A sample stream producer using XADD.
import { createClient } from 'redis';
async function streamProducer() {
const client = createClient();
await client.connect();
let num = 0;
while (num < 1000) {
// * = Let Redis generate a timestamp ID for this new entry.
let id = await client.xAdd('mystream', '*', {
num: `${num}`
// Other name/value pairs can go here as required...
});
console.log(`Added ${id} to the stream.`);
num += 1;
}
await client.quit();
}
streamProducer();