从redis命令中的数组返回中获取数据

时间:2015-04-03 07:31:58

标签: javascript redis

我有一个代码

var redis = require("redis"), client = redis.createClient(6379, '192.168.1.48');
client.on("error", function (err) {
    console.log("Error " + err);
});
    client.sadd("hoang","post:1");
    client.sadd("hoang","post:2");
    client.sadd("hoang","post:3");
    client.sadd("hoang","post:4");
    client.sadd("hoang","post:5");
    client.sadd("hoang","post:7");

    client.sadd("lan","post:1");
    client.sadd("lan","post:2");
    client.sadd("lan","post:3");
    client.sadd("lan","post:4");
    client.sadd("lan","post:5");
    client.sadd("lan","post:6");

    var arr = client.sinter("hoang","lan");
    console.log(arr.length);

和控制台打印

  

未定义

如何从redis命令中获取数组。

1 个答案:

答案 0 :(得分:0)

我认为client.sinter不返回值,需要回调函数,如:

client.sinter(["hoang","lan"], function(err, res){
  console.log(res, res.length);
})

如果您需要更多信息,请提供您正在使用的redis客户端的链接。