You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
* #2287 Add example scripts showing pub/sub usage. https://github.com/redis/node-redis/issues/2287 * #2287 Add example scripts showing pub/sub usage. Fixing comments requested Adding client.connect() to pubsub-subscriber.js Reformatting Readme updating logging in pubsub-publisher.js * #2287 Add example scripts showing pub/sub usage. Fix publish and subscriber Update tidy up comments * Update examples/pubsub-subscriber.js Making suggested changes Co-authored-by: Simon Prickett <simon@crudworks.org> Co-authored-by: Simon Prickett <simon@crudworks.org> Closes #2287.
This commit is contained in:
20
examples/pubsub-publisher.js
Normal file
20
examples/pubsub-publisher.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// A sample publisher using the publish function to put message on different channels.
|
||||
// https://redis.io/commands/publish/
|
||||
import { createClient } from 'redis';
|
||||
|
||||
const client = createClient();
|
||||
|
||||
await client.connect();
|
||||
|
||||
// Declare constant variables for the name of the clients we will publish to as they will be required for logging.
|
||||
const channel1 = 'chan1nel';
|
||||
const channel2 = 'chan2nel';
|
||||
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
// 1st channel created to publish 10000 messages.
|
||||
await client.publish(channel1, `channel1_message_${i}`);
|
||||
console.log(`publishing message on ${channel1}`);
|
||||
// 2nd channel created to publish 10000 messages.
|
||||
await client.publish(channel2, `channel2_message_${i}`);
|
||||
console.log(`publishing message on ${channel2}`);
|
||||
}
|
Reference in New Issue
Block a user