使用节点以redis显示设置值

时间:2012-10-11 07:57:48

标签: node.js redis

我遇到了一个简单的基本redis节点程序。代码是

var redis = require("redis"), client = redis.createClient();`
client.on("error", function (err) {
console.log("Error " + err);
});
client.sadd("string key1", "Hello1", redis.print);
client.sadd("string key1", "Hello2", redis.print);
client.sadd("string key2", "Hi1", redis.print);
client.sadd("string key2", "Hi2", redis.print);
client.smembers("string key1");
}

如何在控制台中显示添加的集。我需要像

这样的输出

"string key1" Hello1, Hello2

"string key2" hi1, hi2

请帮我解释一下代码。请

1 个答案:

答案 0 :(得分:0)

client.multi()
    .smembers("string key1")
    .smembers("string key2")
    .exec(function (err, replies) {
    console.log("MULTI got " + replies.length + " replies");
    replies.forEach(function (reply, index) {
        console.log("Reply " + index + ": " + reply.toString());
    });
    });

此处有更多示例https://github.com/mranney/node_redis/tree/master/examples