You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Make return_buffers work with ints
This commit is contained in:
@@ -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);
|
||||
|
||||
|
32
test.js
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));
|
||||
});
|
||||
|
Reference in New Issue
Block a user