在 redis-cli 客户端的结果与 node 中运行的结果不一样。
源码
源码
subscribe.js
const subscribes = () => {
setInterval(() => {
// subscribe
client.subscribe('redisChat', (err, replies) => {
if (err) {
throw new Error(err)
}
console.log(`subscribe >>>`, replies)
})
}, 1000)
}
subscribes()
publish.js
let i = 0
const publishes = () => {
setInterval(() => {
// publish
client.publish('redisChat', 'hello, i m here' + i, (err, reply) => {
if (err) {
throw new Error(err)
}
console.log(`publish >>>`, reply)
})
i++
}, 1000)
}
publishes()