Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make return_buffers work with ints

  • Loading branch information...
commit 7f3f11f9b1ff51e6d098ae1e8a75c65fc532a8ef 1 parent 252a77e
@mjackson mjackson authored
Showing with 35 additions and 7 deletions.
  1. +7 −3 lib/parser/javascript.js
  2. +28 −4 test.js
View
10 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;
}
View
32 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));
});
Please sign in to comment.
Something went wrong with that request. Please try again.