【问题标题】:Display set values in redis using node使用节点在redis中显示设置值
【发布时间】:2023-03-21 16:49:02
【问题描述】:

我被一个简单的基本 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

请帮我写代码。请

【问题讨论】:

    标签: node.js redis


    【解决方案1】:
    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-21
      • 2019-05-24
      相关资源
      最近更新 更多