差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版 | ||
it:server:redis [2022-08-17 10:56] – [加密访问] goldentianya | it:server:redis [2022-08-17 14:31] (当前版本) – [Node.js 使用] goldentianya | ||
---|---|---|---|
行 41: | 行 41: | ||
// 发布 | // 发布 | ||
redis 127.0.0.1: | redis 127.0.0.1: | ||
+ | </ | ||
+ | |||
+ | ===== Node.js 使用 ===== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | <code > | ||
+ | var redis = require(' | ||
+ | |||
+ | var client = redis.createClient(" | ||
+ | client.on(' | ||
+ | // | ||
+ | // | ||
+ | // | ||
+ | }); | ||
+ | |||
+ | var client1 = redis.createClient(" | ||
+ | client1.on(' | ||
+ | client1.subscribe(" | ||
+ | }); | ||
+ | client1.on(" | ||
+ | console.log(" | ||
+ | if (message == " | ||
+ | client.publish(" | ||
+ | } | ||
+ | if (message == " | ||
+ | client1.unsubscribe(" | ||
+ | console.log(" | ||
+ | // | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | var client2 = redis.createClient(" | ||
+ | client2.on(' | ||
+ | client2.psubscribe(" | ||
+ | }); | ||
+ | client2.on(" | ||
+ | console.log(" | ||
+ | if (message == " | ||
+ | client2.punsubscribe(" | ||
+ | console.log(" | ||
+ | // | ||
+ | } | ||
+ | }); | ||
+ | |||
</ | </ |