You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-07-31 05:44:24 +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.
21 lines
777 B
JavaScript
21 lines
777 B
JavaScript
// 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}`);
|
|
}
|