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

Add warnings and handle protocol errors gracefuly

This commit is contained in:
Ruben Bridgewater
2016-01-21 22:28:26 +01:00
parent 8a43dea9be
commit 8dcf06754d
8 changed files with 106 additions and 46 deletions

View File

@@ -2,31 +2,23 @@
// hgetall converts its replies to an Object. If the reply is empty, null is returned.
function replyToObject(reply) {
var obj = {}, j, jl, key, val;
if (reply.length === 0 || !Array.isArray(reply)) {
if (reply.length === 0 || !Array.isArray(reply)) { // TODO: Check why the isArray check is needed and what value reply has in that case
return null;
}
for (j = 0, jl = reply.length; j < jl; j += 2) {
key = reply[j].toString('binary');
val = reply[j + 1];
obj[key] = val;
var obj = {};
for (var j = 0; j < reply.length; j += 2) {
obj[reply[j].toString('binary')] = reply[j + 1];
}
return obj;
}
function replyToStrings(reply) {
var i;
if (Buffer.isBuffer(reply)) {
return reply.toString();
}
if (Array.isArray(reply)) {
var res = new Array(reply.length);
for (i = 0; i < reply.length; i++) {
for (var i = 0; i < reply.length; i++) {
// Recusivly call the function as slowlog returns deep nested replies
res[i] = replyToStrings(reply[i]);
}