0

我坚持使用一个简单的基本 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

请帮我写代码。请

4

1 回答 1

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

于 2012-10-11T11:50:05.527 回答