From 79511b449943ab6245ccdd4a12b8dee7ad3ec70e Mon Sep 17 00:00:00 2001 From: Matt Ranney Date: Tue, 30 Nov 2010 11:47:52 -0800 Subject: [PATCH] Fix parser bug after failed EXEC. --- bench.js | 114 --------------------------------------------------- changelog.md | 4 ++ index.js | 3 +- package.json | 2 +- test.js | 14 +++++-- 5 files changed, 17 insertions(+), 120 deletions(-) delete mode 100644 bench.js diff --git a/bench.js b/bench.js deleted file mode 100644 index f7153dfa6a..0000000000 --- a/bench.js +++ /dev/null @@ -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(); -} - diff --git a/changelog.md b/changelog.md index 5d1c9172ac..072954b4ba 100644 --- a/changelog.md +++ b/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. diff --git a/index.js b/index.js index b2013e2434..2046ee6a0d 100644 --- a/index.js +++ b/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; diff --git a/package.json b/package.json index 1682b10c57..e52cbaf75f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name" : "redis", - "version" : "0.3.8", + "version" : "0.3.9", "description" : "Redis client library", "author": "Matt Ranney ", "contributors": [ diff --git a/test.js b/test.js index 2cd98162c3..4131ffc770 100644 --- a/test.js +++ b/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);