在 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()