redis NPM Official Address: https://www.npmjs.com/package/redis
let redis = require('redis'); let subscriber; let publisher; let options = { host: "192.168.211.33", port: 6379, password: "123456" } subscriber = redis.createClient(options); //创建订阅客户端 subscriber.on("subscribe", (channel, count) => { console.log("Subscribe # subscribed to " + channel + ", " + count + " total subscriptions"); }); subscriber.on('message', (channel, message) => { console.log('Message # Channel ' + channel + ': ' + message); }); subscriber.on('unsubscribe', (channel, count) => { console.log("Unsubscribe # to " + channel + ", " + count + " total subscriptions"); }); subscriber.on ( "error", (ERR) => { the console.log ( "Redis error:" + the JSON.stringify (ERR)); }); subscriber.subscribe ( 'main_chat_room'); // channel subscription publisher = redis.createClient (options); // Create Post client publisher.publish ( 'main_chat_room', "BBQ IS HERE"); // announced the setTimeout (() => { subscriber.unsubscribe ( 'main_chat_room'); // subscription channel delay cancel }, 15000); the setTimeout (() => { subscriber.quit (); // close the connection publisher.quit (); }, 20000);