5

How could one retrieve various hashes from Redis in Node.js through node-redis? The best way of retrieving various hashes seems to be pipelines but I have not found how to use them in Node.

Community
  • 1
  • 1
brandizzi
  • 26,083
  • 8
  • 103
  • 158

1 Answers1

10

You can achieve that using the multi command to queue the hash retrieval commands:

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());
  });
});
Flion
  • 10,468
  • 13
  • 48
  • 68
alessioalex
  • 62,577
  • 16
  • 155
  • 122
  • 3
    Just to mention a few typos in the "multi_queue" variable name, sometimes "multi_queue", "multiqueue", or "multi", all for the same thing. – darma Oct 23 '13 at 17:34