【问题标题】:Retrieving various hashes from Redis in Node.js在 Node.js 中从 Redis 检索各种哈希
【发布时间】:2016-08-31 17:14:37
【问题描述】:

如何通过node-redis 从 Node.js 中的 Redis 检索各种哈希?检索各种哈希的最佳方法似乎是pipelines,但我还没有找到如何在 Node 中使用它们。

【问题讨论】:

    标签: node.js redis


    【解决方案1】:

    您可以使用multi 命令对哈希检索命令进行排队:

    var redis  = require("redis"),
        client = redis.createClient(),
        multi_queue;
    
    multi_queue = client.multi();
    ...
    for (key in keys) {
      multi_queue.hgetall(key);
    }
    
    multi_queue.exec(function (err, replies) {
      console.log("MULTI got " + replies.length + " replies");
      replies.forEach(function (reply, index) {
        console.log("Reply " + index + ": " + reply.toString());
      });
    });
    

    【讨论】:

    • 只是提到“multi_queue”变量名中的一些拼写错误,有时是“multi_queue”、“multiqueue”或“multi”,都是为了同一件事。
    猜你喜欢
    • 2014-01-02
    • 2011-10-26
    • 2015-11-12
    • 1970-01-01
    • 2011-11-13
    • 2018-09-04
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多