You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Added option to disable offline queue
Signed-off-by: DTrejo <david.trejo@voxer.com>
This commit is contained in:
committed by
DTrejo
parent
eb005b10df
commit
83dc4c999b
9
index.js
9
index.js
@@ -50,6 +50,8 @@ function RedisClient(stream, options) {
|
||||
if (options.connect_timeout && !isNaN(options.connect_timeout) && options.connect_timeout > 0) {
|
||||
this.connect_timeout = +options.connect_timeout;
|
||||
}
|
||||
this.enable_offline_queue = this.options.enable_offline_queue || true;
|
||||
|
||||
this.initialize_retry_vars();
|
||||
this.pub_sub_mode = false;
|
||||
this.subscription_set = {};
|
||||
@@ -661,11 +663,18 @@ RedisClient.prototype.send_command = function (command, args, callback) {
|
||||
if (!stream.writable) {
|
||||
console.log("send command: stream is not writeable.");
|
||||
}
|
||||
}
|
||||
|
||||
if (this.enable_offline_queue) {
|
||||
if (exports.debug_mode) {
|
||||
console.log("Queueing " + command + " for next server connection.");
|
||||
}
|
||||
this.offline_queue.push(command_obj);
|
||||
this.should_buffer = true;
|
||||
} else {
|
||||
command_obj.callback(new Error('send command: stream is not writeable.'));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
42
test.js
42
test.js
@@ -1377,6 +1377,48 @@ tests.HMSET_THROWS_ON_NON_STRINGS = function () {
|
||||
next(name);
|
||||
};
|
||||
|
||||
tests.ENABLE_OFFLINE_QUEUE_TRUE = function () {
|
||||
var name = "ENABLE_OFFLINE_QUEUE_TRUE";
|
||||
var cli = redis.createClient(9999, null, {
|
||||
max_attempts: 1
|
||||
// default :)
|
||||
// enable_offline_queue: true
|
||||
});
|
||||
cli.on('error', function(e) {
|
||||
// ignore, b/c expecting a "can't connect" error
|
||||
});
|
||||
return setTimeout(function() {
|
||||
cli.set(name, name, function(err, result) {
|
||||
assert.ifError(err);
|
||||
});
|
||||
|
||||
return setTimeout(function(){
|
||||
assert.strictEqual(cli.offline_queue.length, 1);
|
||||
return next(name);
|
||||
}, 25);
|
||||
}, 50);
|
||||
};
|
||||
|
||||
tests.ENABLE_OFFLINE_QUEUE_FALSE = function () {
|
||||
var name = "ENABLE_OFFLINE_QUEUE_FALSE";
|
||||
var cli = redis.createClient(9999, null, {
|
||||
max_attempts: 1,
|
||||
enable_offline_queue: false
|
||||
});
|
||||
cli.on('error', function() {
|
||||
// ignore, see above
|
||||
});
|
||||
assert.throws(function () {
|
||||
cli.set(name, name)
|
||||
})
|
||||
assert.doesNotThrow(function () {
|
||||
cli.set(name, name, function (err) {
|
||||
// should callback with an error
|
||||
assert.ok(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// TODO - need a better way to test auth, maybe auto-config a local Redis server or something.
|
||||
// Yes, this is the real password. Please be nice, thanks.
|
||||
tests.auth = function () {
|
||||
|
Reference in New Issue
Block a user