Skip to content

Commit 0d4d4d7

Browse files
author
Ruben Bridgewater
committed
Fix multi not being executed on node 0.10 if not yet ready. Closes #889
1 parent a408235 commit 0d4d4d7

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
## v.2.2.3 - 14 Oct, 2015
5+
6+
Bugfixes
7+
8+
- Fix multi not being executed on Node 0.10.x if node_redis not yet ready ([@BridgeAR](https://github.com/BridgeAR))
9+
410
## v.2.2.2 - 14 Oct, 2015
511

612
Bugfixes

index.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ function RedisClient(stream, options) {
3838

3939
this.pipeline = 0;
4040
if (!stream.cork) {
41-
stream.cork = function noop() {
42-
self.pipeline_queue = new Queue();
43-
};
41+
this.cork = function noop (len) {};
42+
this.once('ready', function () {
43+
self.cork = function (len) {
44+
self.pipeline = len;
45+
self.pipeline_queue = new Queue(len);
46+
};
47+
});
4448
stream.uncork = function noop() {};
4549
this.write = this.writeStream;
4650
}
@@ -128,6 +132,10 @@ RedisClient.prototype.install_stream_listeners = function() {
128132
});
129133
};
130134

135+
RedisClient.prototype.cork = function (len) {
136+
this.stream.cork();
137+
};
138+
131139
RedisClient.prototype.initialize_retry_vars = function () {
132140
this.retry_timer = null;
133141
this.retry_totaltime = 0;
@@ -1074,8 +1082,7 @@ Multi.prototype.exec_transaction = function (callback) {
10741082
var cb;
10751083
this.errors = [];
10761084
this.callback = callback;
1077-
this._client.stream.cork();
1078-
this._client.pipeline = len + 2;
1085+
this._client.cork(len + 2);
10791086
this.wants_buffers = new Array(len);
10801087
this.send_command('multi', []);
10811088
// drain queue, callback will catch 'QUEUED' or error
@@ -1192,8 +1199,7 @@ Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = funct
11921199
return true;
11931200
}
11941201
this.results = new Array(len);
1195-
this._client.stream.cork();
1196-
this._client.pipeline = len;
1202+
this._client.cork(len);
11971203
var lastCallback = function (cb) {
11981204
return function (err, res) {
11991205
cb(err, res);

test/commands/multi.spec.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ describe("The 'multi' method", function () {
5050
describe("when connected", function () {
5151
var client;
5252

53+
beforeEach(function (done) {
54+
client = redis.createClient.apply(redis.createClient, args);
55+
client.once("connect", done);
56+
});
57+
58+
afterEach(function () {
59+
client.end();
60+
});
61+
62+
it("executes a pipelined multi properly in combination with the offline queue", function (done) {
63+
var multi1 = client.multi();
64+
multi1.set("m1", "123");
65+
multi1.get('m1');
66+
multi1.exec(done);
67+
});
68+
});
69+
70+
describe("when ready", function () {
71+
var client;
72+
5373
beforeEach(function (done) {
5474
client = redis.createClient.apply(redis.createClient, args);
5575
client.once("ready", function () {
@@ -73,7 +93,7 @@ describe("The 'multi' method", function () {
7393
assert.strictEqual(notBuffering, true);
7494
});
7595

76-
it("runs normal calls inbetween multis", function (done) {
96+
it("runs normal calls in-between multis", function (done) {
7797
var multi1 = client.multi();
7898
multi1.set("m1", "123");
7999
client.set('m2', '456', done);

0 commit comments

Comments
 (0)