You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Fix parser bug after failed EXEC.
This commit is contained in:
114
bench.js
114
bench.js
@@ -1,114 +0,0 @@
|
|||||||
|
|
||||||
/**
|
|
||||||
* Module dependencies.
|
|
||||||
*/
|
|
||||||
|
|
||||||
var redis = require('./index')
|
|
||||||
, fs = require('fs');
|
|
||||||
|
|
||||||
var client = redis.createClient()
|
|
||||||
, path = '/tmp/redis-bench'
|
|
||||||
, times = 2000
|
|
||||||
, curr = {}
|
|
||||||
, prev;
|
|
||||||
|
|
||||||
var buffers = [
|
|
||||||
new Buffer('hello')
|
|
||||||
, new Buffer(Array(129).join('-'))
|
|
||||||
, new Buffer(Array(257).join('-'))
|
|
||||||
, new Buffer(Array(1025).join('-'))
|
|
||||||
, new Buffer(Array(1025 * 4).join('-'))
|
|
||||||
];
|
|
||||||
|
|
||||||
function next(){
|
|
||||||
var fn = queue.shift();
|
|
||||||
if (fn.length) {
|
|
||||||
if (fn.bufidx === undefined) {
|
|
||||||
fn.bufidx = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fn(buffers[fn.bufidx++], function(label){
|
|
||||||
report(label);
|
|
||||||
next();
|
|
||||||
})
|
|
||||||
|
|
||||||
/* Skip to next function in queue when all
|
|
||||||
* buffer sizes have been benchmarked. */
|
|
||||||
if (fn.bufidx == buffers.length) {
|
|
||||||
fn.bufidx = undefined;
|
|
||||||
} else {
|
|
||||||
queue.unshift(fn);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var queue = [
|
|
||||||
|
|
||||||
// FLUSHALL
|
|
||||||
|
|
||||||
function(){
|
|
||||||
client.flushall(next);
|
|
||||||
},
|
|
||||||
|
|
||||||
// LPUSH
|
|
||||||
|
|
||||||
function(buf, next){
|
|
||||||
var n = times
|
|
||||||
, start = new Date
|
|
||||||
, key = 'list-' + buf.length;
|
|
||||||
while (--n) client.lpush(key, buf);
|
|
||||||
client.lpush(key, buf, function(err, res) {
|
|
||||||
curr['lpush ' + buf.length] = new Date - start;
|
|
||||||
next('lpush ' + buf.length);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// LRANGE
|
|
||||||
|
|
||||||
function(buf, next){
|
|
||||||
var n = times
|
|
||||||
, start = new Date
|
|
||||||
, key = 'list-' + buf.length;
|
|
||||||
while (--n) client.lrange(key, 0, 99);
|
|
||||||
client.lrange(key, 0, 99, function (err, res) {
|
|
||||||
curr['lrange 0 99 (' + buf.length + ' byte entries)'] = new Date - start;
|
|
||||||
next('lrange 0 99 (' + buf.length + ' byte entries)');
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
function(){
|
|
||||||
fs.writeFileSync(path, JSON.stringify(curr), 'ascii');
|
|
||||||
client.end();
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
client.on('connect', function(){
|
|
||||||
try {
|
|
||||||
prev = JSON.parse(fs.readFileSync(path, 'ascii'));
|
|
||||||
} catch (err) {
|
|
||||||
prev = {};
|
|
||||||
}
|
|
||||||
console.log('\n %d:', times);
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
function report(label) {
|
|
||||||
var c = curr[label]
|
|
||||||
, p = prev[label] || c
|
|
||||||
, col = c > p
|
|
||||||
? c > p + 100
|
|
||||||
? 31
|
|
||||||
: 33
|
|
||||||
: 32
|
|
||||||
, synopsis = c > p
|
|
||||||
? '+' + (c - p)
|
|
||||||
: '-' + (p - c);
|
|
||||||
while (synopsis.length + label.length < 20) synopsis = ' ' + synopsis;
|
|
||||||
console.log(' \x1b[' + col + ';1m%s\x1b[0m: %s', label, synopsis);
|
|
||||||
console.log(' \x1b[33mprev\x1b[0m: %d ms', p);
|
|
||||||
console.log(' \x1b[33mcurr\x1b[0m: %d ms', c);
|
|
||||||
console.log();
|
|
||||||
}
|
|
||||||
|
|
@@ -1,6 +1,10 @@
|
|||||||
Changelog
|
Changelog
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
## v0.3.9 - November 30, 2010
|
||||||
|
|
||||||
|
Fix parser bug on failed EXECs.
|
||||||
|
|
||||||
## v0.3.8 - November 10, 2010
|
## v0.3.8 - November 10, 2010
|
||||||
|
|
||||||
Fix for null MULTI response when WATCH condition fails.
|
Fix for null MULTI response when WATCH condition fails.
|
||||||
|
3
index.js
3
index.js
@@ -153,6 +153,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
|
|||||||
this.state = "type";
|
this.state = "type";
|
||||||
if (this.multi_bulk_length <= 0) {
|
if (this.multi_bulk_length <= 0) {
|
||||||
this.send_reply(null);
|
this.send_reply(null);
|
||||||
|
this.multi_bulk_length = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.emit("error", new Error("didn't see LF after NL reading multi bulk count"));
|
this.emit("error", new Error("didn't see LF after NL reading multi bulk count"));
|
||||||
@@ -280,7 +281,7 @@ RedisReplyParser.prototype.add_multi_bulk_reply = function (reply) {
|
|||||||
this.multi_bulk_replies = reply;
|
this.multi_bulk_replies = reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.multi_bulk_nested_length) {
|
if (this.multi_bulk_nested_length > 0) {
|
||||||
this.multi_bulk_nested_replies.push(this.multi_bulk_replies);
|
this.multi_bulk_nested_replies.push(this.multi_bulk_replies);
|
||||||
this.multi_bulk_length = 0;
|
this.multi_bulk_length = 0;
|
||||||
delete this.multi_bulk_replies;
|
delete this.multi_bulk_replies;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
{ "name" : "redis",
|
{ "name" : "redis",
|
||||||
"version" : "0.3.8",
|
"version" : "0.3.9",
|
||||||
"description" : "Redis client library",
|
"description" : "Redis client library",
|
||||||
"author": "Matt Ranney <mjr@ranney.com>",
|
"author": "Matt Ranney <mjr@ranney.com>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
|
14
test.js
14
test.js
@@ -59,6 +59,14 @@ function require_string(str, label) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function require_null(label) {
|
||||||
|
return function (err, results) {
|
||||||
|
assert.strictEqual(null, err, "result sent back unexpected error: " + err);
|
||||||
|
assert.strictEqual(null, results, label + ": " + results + " is not null");
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function require_error(label) {
|
function require_error(label) {
|
||||||
return function (err, results) {
|
return function (err, results) {
|
||||||
assert.notEqual(err, null, label + " err is null, but an error is expected here.");
|
assert.notEqual(err, null, label + " err is null, but an error is expected here.");
|
||||||
@@ -212,12 +220,10 @@ tests.WATCH_MULTI = function () {
|
|||||||
|
|
||||||
if (server_info.versions[0] >= 2 && server_info.versions[1] >= 1) {
|
if (server_info.versions[0] >= 2 && server_info.versions[1] >= 1) {
|
||||||
client.watch(name);
|
client.watch(name);
|
||||||
|
client.incr(name);
|
||||||
var multi = client.multi();
|
var multi = client.multi();
|
||||||
multi.incr(name);
|
multi.incr(name);
|
||||||
client.incr(name);
|
multi.exec(last(name, require_null(name)));
|
||||||
multi.exec(function (err, replies) {
|
|
||||||
next(name);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
console.log("Skipping " + name + " because server version isn't new enough.");
|
console.log("Skipping " + name + " because server version isn't new enough.");
|
||||||
next(name);
|
next(name);
|
||||||
|
Reference in New Issue
Block a user