1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Fixed .multi() to convert HGETALL result to an object

This commit is contained in:
Aivo Paas
2010-10-02 22:00:57 +03:00
parent 8356ecfda8
commit 3495b60047
2 changed files with 33 additions and 5 deletions

View File

@@ -747,7 +747,7 @@ Multi.prototype.exec = function(callback) {
});
}, this);
this.client.send_command("EXEC", function (err, reply) {
this.client.send_command("EXEC", function (err, replies) {
if (err) {
if (callback) {
callback(new Error(err));
@@ -756,15 +756,28 @@ Multi.prototype.exec = function(callback) {
}
}
for (var i = 1, il = self.queue.length, args; i < il; i++) {
args = self.queue[i];
for (var i = 1, il = self.queue.length; i < il; i++) {
var reply = replies[i - 1],
args = self.queue[i];
// Convert HGETALL reply to object
if (reply && args[0] === "HGETALL") {
obj = {};
for (var j = 0, jl = reply.length; j < jl; j += 2) {
key = reply[j].toString();
val = reply[j + 1];
obj[key] = val;
}
replies[i - 1] = reply = obj;
}
if (typeof args[args.length - 1] === "function") {
args[args.length - 1](null, reply[i - 1]);
args[args.length - 1](null, reply);
}
}
if (callback) {
callback(null, reply);
callback(null, replies);
}
});
};

15
test.js
View File

@@ -183,6 +183,21 @@ tests.MULTI_5 = function () {
});
};
tests.MULTI_6 = function () {
var name = "MULTI_6";
client.multi()
.hmset("multihash", "a", "foo", "b", 1)
.hgetall("multihash")
.exec(function (err, replies){
assert.strictEqual(null, err);
assert.equal("OK", replies[0]);
assert.equal(Object.keys(replies[1]).length, 2);
assert.equal("foo", replies[1].a.toString());
assert.equal("1", replies[1].b.toString());
next(name);
});
};
tests.HMGET = function () {
var key = "test hash", name = "HMGET";