gitbhub
github
目录
文件内容
redis-push.js
var redis = require(‘redis’);
var client = redis.createClient(6379,’localhost’);
client.publish(‘testPublish’,’message from publish.js’)
redis-sub1.js
var redis = require(‘redis’);
var client = redis.createClient(6379,’localhost’);
client.subscribe(‘testPublish’)
client.on(‘message’,(channel,msg) => {
console.log(channel)
console.log(msg)
})
redis-sub2.js
var redis = require(‘redis’);
var client = redis.createClient(6379,’localhost’);
client.subscribe(‘testPublish’)
client.on(‘message’,(channel,msg) => {
console.log(channel)
console.log(msg)
})
先订阅
再发布,订阅者就能看到发布者发布过来的信息