From 71763dcd6632d44bd1f6d02479a5e44b317755a5 Mon Sep 17 00:00:00 2001 From: Orion Henry Date: Mon, 27 Sep 2010 08:25:55 -0700 Subject: [PATCH] Send the number of bytes, not characters. Fixes unrecoverable bug if multibyte characters are used. --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e9065d2be1..015944bc62 100644 --- a/index.js +++ b/index.js @@ -593,7 +593,7 @@ RedisClient.prototype.send_command = function () { if (typeof arg !== "string") { arg = String(arg); } - command_str += "$" + arg.length + "\r\n" + arg + "\r\n"; + command_str += "$" + Buffer.byteLength(arg) + "\r\n" + arg + "\r\n"; }); if (exports.debug_mode) { console.log("send command: " + command_str); @@ -624,7 +624,7 @@ RedisClient.prototype.send_command = function () { stream.write("\r\n"); } } else { - stream.write("$" + arg.length + "\r\n" + arg + "\r\n"); + stream.write("$" + Buffer.byteLength(arg) + "\r\n" + arg + "\r\n"); } }); }