From b1d8ff9ae8e57a5cac335baa9ac29dbcaecd5a88 Mon Sep 17 00:00:00 2001 From: Nick Apperson Date: Wed, 7 May 2014 14:14:11 -0500 Subject: [PATCH 1/2] reply_to_object function is broken for binary keys There is currently no way to opt out of the way hgetall works with the node_redis library and if any of the keys have binary, they are incorrectly converted to the charactor 0xFEFF instead. This makes it impossible to fully use HGETALL. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 0291f17be3..13964983e0 100644 --- a/index.js +++ b/index.js @@ -590,7 +590,7 @@ function reply_to_object(reply) { } for (j = 0, jl = reply.length; j < jl; j += 2) { - key = reply[j].toString(); + key = reply[j].toString('binary'); val = reply[j + 1]; obj[key] = val; } From 6f00ff8ffe08bd7440bdb39c9a0c4604af59e9e1 Mon Sep 17 00:00:00 2001 From: Nick Apperson Date: Mon, 12 May 2014 21:25:46 -0500 Subject: [PATCH 2/2] Add a test for binary client hgetall binary keys --- test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test.js b/test.js index e0bcff42aa..540f327d94 100644 --- a/test.js +++ b/test.js @@ -1403,6 +1403,21 @@ tests.HGETALL = function () { }); }; +tests.HGETALL_2 = function () { + var name = "HGETALL (Binary client)"; + bclient.hmset(["bhosts", "mjr", "1", "another", "23", "home", "1234", new Buffer([0xAA, 0xBB, 0x00, 0xF0]), new Buffer([0xCC, 0xDD, 0x00, 0xF0])], require_string("OK", name)); + bclient.HGETALL(["bhosts"], function (err, obj) { + assert.strictEqual(null, err, name + " result sent back unexpected error: " + err); + assert.strictEqual(4, Object.keys(obj).length, name); + assert.strictEqual("1", obj.mjr.toString(), name); + assert.strictEqual("23", obj.another.toString(), name); + assert.strictEqual("1234", obj.home.toString(), name); + assert.strictEqual((new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary'), Object.keys(obj)[3], name); + assert.strictEqual((new Buffer([0xCC, 0xDD, 0x00, 0xF0])).toString('binary'), obj[(new Buffer([0xAA, 0xBB, 0x00, 0xF0])).toString('binary')].toString('binary'), name); + next(name); + }); +}; + tests.HGETALL_MESSAGE = function () { var name = "HGETALL_MESSAGE"; client.hmset("msg_test", {message: "hello"}, require_string("OK", name));