Haris Razis
4 years ago
3 changed files with 40 additions and 1 deletions
@ -0,0 +1,25 @@ |
|||||
|
const redis = require('redis'); |
||||
|
|
||||
|
const subscriber = redis.createClient(); |
||||
|
const publisher = redis.createClient(); |
||||
|
|
||||
|
let messageCount = 0; |
||||
|
|
||||
|
subscriber.on('subscribe', function (channel, count) { |
||||
|
publisher.publish('a channel', 'a message'); |
||||
|
publisher.publish('a channel', 'another message'); |
||||
|
}); |
||||
|
|
||||
|
subscriber.on('message', function (channel, message) { |
||||
|
messageCount += 1; |
||||
|
|
||||
|
console.log('Subscriber received message in channel \'' + channel + '\': ' + message); |
||||
|
|
||||
|
if (messageCount === 2) { |
||||
|
subscriber.unsubscribe(); |
||||
|
subscriber.quit(); |
||||
|
publisher.quit(); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
subscriber.subscribe('a channel'); |
Loading…
Reference in new issue