diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index 9acfa1f188..c9ef7ab94d 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -37,7 +37,7 @@ function small_toString(buf, start, end) { ReplyParser.prototype._parseResult = function (type) { var start, end, offset, packetHeader; - + if (type === 43 || type === 45) { // + or - // up to the delimiter end = this._packetEndOffset() - 1; @@ -73,6 +73,10 @@ ReplyParser.prototype._parseResult = function (type) { throw new Error("too far"); } + if (this.options.return_buffers) { + return this._buffer.slice(start, end); + } + // return the coerced numeric value return +small_toString(this._buffer, start, end); } else if (type === 36) { // $ @@ -177,7 +181,7 @@ ReplyParser.prototype.execute = function (buffer) { break; } - this.send_reply(+ret); + this.send_reply(ret); } else if (type === 36) { // $ ret = this._parseResult(type); @@ -246,7 +250,7 @@ ReplyParser.prototype.append = function (newBuffer) { this._buffer.copy(tmpBuffer, 0, this._offset); newBuffer.copy(tmpBuffer, remaining, 0); - + this._buffer = tmpBuffer; } diff --git a/test.js b/test.js index db6e9bbf76..94bd19d682 100644 --- a/test.js +++ b/test.js @@ -1,8 +1,12 @@ /*global require console setTimeout process Buffer */ +var PORT = 6379; +var HOST = '127.0.0.1'; + var redis = require("./index"), - client = redis.createClient(), - client2 = redis.createClient(), - client3 = redis.createClient(), + client = redis.createClient(PORT, HOST), + client2 = redis.createClient(PORT, HOST), + client3 = redis.createClient(PORT, HOST), + bclient = redis.createClient(PORT, HOST, { return_buffers: true }), assert = require("assert"), crypto = require("crypto"), util = require("./lib/util"), @@ -85,7 +89,7 @@ next = function next(name) { run_next_test(); }; -// Tests are run in the order they are defined. So FLUSHDB should be stay first. +// Tests are run in the order they are defined, so FLUSHDB should always be first. tests.FLUSHDB = function () { var name = "FLUSHDB"; @@ -97,6 +101,20 @@ tests.FLUSHDB = function () { client.dbsize(last(name, require_number(0, name))); }; +tests.INCR = function () { + var name = "INCR"; + + // Test incr with the maximum JavaScript number value. Since we are + // returning buffers we should get back one more as a Buffer. + bclient.set("seq", "9007199254740992", function (err, result) { + assert.strictEqual(result.toString(), "OK"); + bclient.incr("seq", function (err, result) { + assert.strictEqual("9007199254740993", result.toString()); + next(name); + }); + }); +}; + tests.MULTI_1 = function () { var name = "MULTI_1", multi1, multi2; @@ -1607,6 +1625,7 @@ run_next_test = function run_next_test() { console.log('\n completed \x1b[32m%d\x1b[0m tests in \x1b[33m%d\x1b[0m ms\n', test_count, new Date() - all_start); client.quit(); client2.quit(); + bclient.quit(); } }; @@ -1636,6 +1655,11 @@ client3.on("error", function (err) { console.error("client3: " + err.stack); process.exit(); }); +bclient.on("error", function (err) { + console.error("bclient: " + err.stack); + process.exit(); +}); + client.on("reconnecting", function (params) { console.log("reconnecting: " + util.inspect(params)); });