- subscribe
- publish
- on(‘message’)
const redis = require('redis');
const client1 = redis.createClient(6379, 'localhost');
const client2 = redis.createClient(6379, 'localhost');
// 订阅消息
client1.subscribe('channel');
client1.on('message', (channel, message) => {
console.log('client message', channel, message);
});
// 取消订阅
client1.unsubscribe('channel');
// publish 发布消息
client2.publish('chanel', 'hello longwen');