Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix parser bug after failed EXEC.

  • Loading branch information...
commit 79511b449943ab6245ccdd4a12b8dee7ad3ec70e 1 parent 4815295
@mranney authored
Showing with 17 additions and 120 deletions.
  1. +0 −114 bench.js
  2. +4 −0 changelog.md
  3. +2 −1  index.js
  4. +1 −1  package.json
  5. +10 −4 test.js
View
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();
-}
-
View
4 changelog.md
@@ -1,6 +1,10 @@
Changelog
=========
+## v0.3.9 - November 30, 2010
+
+Fix parser bug on failed EXECs.
+
## v0.3.8 - November 10, 2010
Fix for null MULTI response when WATCH condition fails.
View
3  index.js
@@ -153,6 +153,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
this.state = "type";
if (this.multi_bulk_length <= 0) {
this.send_reply(null);
+ this.multi_bulk_length = 0;
}
} else {
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;
}
- 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_length = 0;
delete this.multi_bulk_replies;
View
2  package.json
@@ -1,5 +1,5 @@
{ "name" : "redis",
- "version" : "0.3.8",
+ "version" : "0.3.9",
"description" : "Redis client library",
"author": "Matt Ranney <mjr@ranney.com>",
"contributors": [
View
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) {
return function (err, results) {
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) {
client.watch(name);
+ client.incr(name);
var multi = client.multi();
multi.incr(name);
- client.incr(name);
- multi.exec(function (err, replies) {
- next(name);
- });
+ multi.exec(last(name, require_null(name)));
} else {
console.log("Skipping " + name + " because server version isn't new enough.");
next(name);
Please sign in to comment.
Something went wrong with that request. Please try again.