-
Notifications
You must be signed in to change notification settings - Fork 0
/
sub.js
34 lines (28 loc) · 888 Bytes
/
sub.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var Redis = require("ioredis");
var fs = require("fs");
var client1 = new Redis('redis:https://redis:6379/0');
var client2 = new Redis('redis:https://redis:6379/0');
var len = 0;
client1.on("message", function (channel, message) {
console.log(channel + ": " + message);
getValue(channel);
});
//var myDate = new Date(); //获取当前时间
//console.log(myDate);
client1.subscribe("usr");
client1.subscribe("like");
client1.subscribe("dislike");
client1.subscribe("test-channel");
function getValue(channel)
{
client2.llen(channel,function(err,reply){ //回调函数形式获取结果,可以使用redis.print来查看结果
//console.log(reply);
var client = new Redis('redis:https://redis:6379/0');
for(var i=0;i<reply;i++)
{
client.rpop(channel,function(err,reply){
console.log(reply);
});
}
});
}