egg(89)–egg之redis的发布和订阅

48次阅读

共计 564 个字符,预计需要花费 2 分钟才能阅读完成。

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)
})

先订阅

再发布,订阅者就能看到发布者发布过来的信息

正文完
 0