Skip to content

Commit

Permalink
Use binary encoding for arg serialization when not a Buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
fictorial committed May 7, 2010
1 parent c0ef7d6 commit bd86792
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions lib/redis-client.js
Expand Up @@ -714,9 +714,9 @@ Client.prototype.sendCommand = function () {
offset += this.requestBuffer.asciiWrite(CRLF, offset);
} else if (arg.toString) {
var asString = arg.toString();
var serialized = '$' + Buffer.byteLength(asString) + CRLF + asString + CRLF;
ensureSpaceFor(Buffer.byteLength(serialized));
offset += this.requestBuffer.utf8Write(serialized, offset);
var serialized = '$' + Buffer.byteLength(asString, "binary") + CRLF + asString + CRLF;
ensureSpaceFor(Buffer.byteLength(serialized, "binary"));
offset += this.requestBuffer.binaryWrite(serialized, offset);
}
}

Expand Down
10 changes: 2 additions & 8 deletions test/test.js
Expand Up @@ -1743,13 +1743,7 @@ var allTestFunctions = [
function testLargeGetSet() {
showTestBanner("testLargeGetSet");

var fileContents = fs.readFileSync(__filename);

// if (Buffer.byteLength(fileContents) < client.requestBuffer.length) {
// sys.debug(Buffer.byteLength(fileContents));
// sys.debug(client.requestBuffer.length);
// assert.fail("the request buffer will not be forced to grow", "testGET (large; 0)");
// }
var fileContents = fs.readFileSync(__filename, "binary");

var wasDebugMode = redisclient.debugMode;
redisclient.debugMode = false;
Expand All @@ -1763,7 +1757,7 @@ function testLargeGetSet() {

client.get('largetestfile', function (err, value) {
if (err) assert.fail(err, "testGET (large; 3)");
checkEqual(value.utf8Slice(0, value.length), fileContents, "testGET (large; 4)");
checkEqual(value.binarySlice(0, value.length), fileContents, "testGET (large; 4)");
redisclient.debugMode = wasDebugMode;
testStoreAnImage();
});
Expand Down

0 comments on commit bd86792

Please sign in to comment.