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 multi not being executed on node 0.10 if not yet ready. Closes #889
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
## v.2.2.3 - 14 Oct, 2015
|
||||
|
||||
Bugfixes
|
||||
|
||||
- Fix multi not being executed on Node 0.10.x if node_redis not yet ready ([@BridgeAR](https://github.com/BridgeAR))
|
||||
|
||||
## v.2.2.2 - 14 Oct, 2015
|
||||
|
||||
Bugfixes
|
||||
|
20
index.js
20
index.js
@@ -38,9 +38,13 @@ function RedisClient(stream, options) {
|
||||
|
||||
this.pipeline = 0;
|
||||
if (!stream.cork) {
|
||||
stream.cork = function noop() {
|
||||
self.pipeline_queue = new Queue();
|
||||
};
|
||||
this.cork = function noop (len) {};
|
||||
this.once('ready', function () {
|
||||
self.cork = function (len) {
|
||||
self.pipeline = len;
|
||||
self.pipeline_queue = new Queue(len);
|
||||
};
|
||||
});
|
||||
stream.uncork = function noop() {};
|
||||
this.write = this.writeStream;
|
||||
}
|
||||
@@ -128,6 +132,10 @@ RedisClient.prototype.install_stream_listeners = function() {
|
||||
});
|
||||
};
|
||||
|
||||
RedisClient.prototype.cork = function (len) {
|
||||
this.stream.cork();
|
||||
};
|
||||
|
||||
RedisClient.prototype.initialize_retry_vars = function () {
|
||||
this.retry_timer = null;
|
||||
this.retry_totaltime = 0;
|
||||
@@ -1074,8 +1082,7 @@ Multi.prototype.exec_transaction = function (callback) {
|
||||
var cb;
|
||||
this.errors = [];
|
||||
this.callback = callback;
|
||||
this._client.stream.cork();
|
||||
this._client.pipeline = len + 2;
|
||||
this._client.cork(len + 2);
|
||||
this.wants_buffers = new Array(len);
|
||||
this.send_command('multi', []);
|
||||
// drain queue, callback will catch 'QUEUED' or error
|
||||
@@ -1192,8 +1199,7 @@ Multi.prototype.exec = Multi.prototype.EXEC = Multi.prototype.exec_batch = funct
|
||||
return true;
|
||||
}
|
||||
this.results = new Array(len);
|
||||
this._client.stream.cork();
|
||||
this._client.pipeline = len;
|
||||
this._client.cork(len);
|
||||
var lastCallback = function (cb) {
|
||||
return function (err, res) {
|
||||
cb(err, res);
|
||||
|
@@ -50,6 +50,26 @@ describe("The 'multi' method", function () {
|
||||
describe("when connected", function () {
|
||||
var client;
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(redis.createClient, args);
|
||||
client.once("connect", done);
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
client.end();
|
||||
});
|
||||
|
||||
it("executes a pipelined multi properly in combination with the offline queue", function (done) {
|
||||
var multi1 = client.multi();
|
||||
multi1.set("m1", "123");
|
||||
multi1.get('m1');
|
||||
multi1.exec(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe("when ready", function () {
|
||||
var client;
|
||||
|
||||
beforeEach(function (done) {
|
||||
client = redis.createClient.apply(redis.createClient, args);
|
||||
client.once("ready", function () {
|
||||
@@ -73,7 +93,7 @@ describe("The 'multi' method", function () {
|
||||
assert.strictEqual(notBuffering, true);
|
||||
});
|
||||
|
||||
it("runs normal calls inbetween multis", function (done) {
|
||||
it("runs normal calls in-between multis", function (done) {
|
||||
var multi1 = client.multi();
|
||||
multi1.set("m1", "123");
|
||||
client.set('m2', '456', done);
|
||||
|
Reference in New Issue
Block a user