You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add stream examples. (#1830)
* Adds stream consumer and producer scripts to doc. * Updated build command example. * Adds stream producer example. * Adds basic stream consumer example. * Added isolated execution. * Update README.md * Update stream-consumer.js Co-authored-by: Leibale Eidelman <leibale1998@gmail.com>
This commit is contained in:
28
examples/stream-producer.js
Normal file
28
examples/stream-producer.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// A sample stream producer using XADD.
|
||||
|
||||
import { createClient } from 'redis';
|
||||
|
||||
async function streamProducer() {
|
||||
const client = createClient();
|
||||
|
||||
await client.connect();
|
||||
await client.del('mystream');
|
||||
|
||||
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();
|
||||
|
Reference in New Issue
Block a user