You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Make return_buffers work with ints
This commit is contained in:
@@ -37,7 +37,7 @@ function small_toString(buf, start, end) {
|
|||||||
|
|
||||||
ReplyParser.prototype._parseResult = function (type) {
|
ReplyParser.prototype._parseResult = function (type) {
|
||||||
var start, end, offset, packetHeader;
|
var start, end, offset, packetHeader;
|
||||||
|
|
||||||
if (type === 43 || type === 45) { // + or -
|
if (type === 43 || type === 45) { // + or -
|
||||||
// up to the delimiter
|
// up to the delimiter
|
||||||
end = this._packetEndOffset() - 1;
|
end = this._packetEndOffset() - 1;
|
||||||
@@ -73,6 +73,10 @@ ReplyParser.prototype._parseResult = function (type) {
|
|||||||
throw new Error("too far");
|
throw new Error("too far");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.options.return_buffers) {
|
||||||
|
return this._buffer.slice(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
// return the coerced numeric value
|
// return the coerced numeric value
|
||||||
return +small_toString(this._buffer, start, end);
|
return +small_toString(this._buffer, start, end);
|
||||||
} else if (type === 36) { // $
|
} else if (type === 36) { // $
|
||||||
@@ -177,7 +181,7 @@ ReplyParser.prototype.execute = function (buffer) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.send_reply(+ret);
|
this.send_reply(ret);
|
||||||
} else if (type === 36) { // $
|
} else if (type === 36) { // $
|
||||||
ret = this._parseResult(type);
|
ret = this._parseResult(type);
|
||||||
|
|
||||||
@@ -246,7 +250,7 @@ ReplyParser.prototype.append = function (newBuffer) {
|
|||||||
|
|
||||||
this._buffer.copy(tmpBuffer, 0, this._offset);
|
this._buffer.copy(tmpBuffer, 0, this._offset);
|
||||||
newBuffer.copy(tmpBuffer, remaining, 0);
|
newBuffer.copy(tmpBuffer, remaining, 0);
|
||||||
|
|
||||||
this._buffer = tmpBuffer;
|
this._buffer = tmpBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
test.js
32
test.js
@@ -1,8 +1,12 @@
|
|||||||
/*global require console setTimeout process Buffer */
|
/*global require console setTimeout process Buffer */
|
||||||
|
var PORT = 6379;
|
||||||
|
var HOST = '127.0.0.1';
|
||||||
|
|
||||||
var redis = require("./index"),
|
var redis = require("./index"),
|
||||||
client = redis.createClient(),
|
client = redis.createClient(PORT, HOST),
|
||||||
client2 = redis.createClient(),
|
client2 = redis.createClient(PORT, HOST),
|
||||||
client3 = redis.createClient(),
|
client3 = redis.createClient(PORT, HOST),
|
||||||
|
bclient = redis.createClient(PORT, HOST, { return_buffers: true }),
|
||||||
assert = require("assert"),
|
assert = require("assert"),
|
||||||
crypto = require("crypto"),
|
crypto = require("crypto"),
|
||||||
util = require("./lib/util"),
|
util = require("./lib/util"),
|
||||||
@@ -85,7 +89,7 @@ next = function next(name) {
|
|||||||
run_next_test();
|
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 () {
|
tests.FLUSHDB = function () {
|
||||||
var name = "FLUSHDB";
|
var name = "FLUSHDB";
|
||||||
@@ -97,6 +101,20 @@ tests.FLUSHDB = function () {
|
|||||||
client.dbsize(last(name, require_number(0, name)));
|
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 () {
|
tests.MULTI_1 = function () {
|
||||||
var name = "MULTI_1", multi1, multi2;
|
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);
|
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();
|
client.quit();
|
||||||
client2.quit();
|
client2.quit();
|
||||||
|
bclient.quit();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1636,6 +1655,11 @@ client3.on("error", function (err) {
|
|||||||
console.error("client3: " + err.stack);
|
console.error("client3: " + err.stack);
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
|
bclient.on("error", function (err) {
|
||||||
|
console.error("bclient: " + err.stack);
|
||||||
|
process.exit();
|
||||||
|
});
|
||||||
|
|
||||||
client.on("reconnecting", function (params) {
|
client.on("reconnecting", function (params) {
|
||||||
console.log("reconnecting: " + util.inspect(params));
|
console.log("reconnecting: " + util.inspect(params));
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user