You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
Remove deprecated drain event
This commit is contained in:
committed by
Ruben Bridgewater
parent
b72dd195a8
commit
98527e0fc5
18
README.md
18
README.md
@@ -158,17 +158,6 @@ So please attach the error listener to node_redis.
|
|||||||
|
|
||||||
`client` will emit `end` when an established Redis server connection has closed.
|
`client` will emit `end` when an established Redis server connection has closed.
|
||||||
|
|
||||||
### "drain" (deprecated)
|
|
||||||
|
|
||||||
`client` will emit `drain` when the TCP connection to the Redis server has been buffering, but is now
|
|
||||||
writable. This event can be used to stream commands in to Redis and adapt to backpressure.
|
|
||||||
|
|
||||||
If the stream is buffering `client.should_buffer` is set to true. Otherwise the variable is always set to false.
|
|
||||||
That way you can decide when to reduce your send rate and resume sending commands when you get `drain`.
|
|
||||||
|
|
||||||
You can also check the return value of each command as it will also return the backpressure indicator (deprecated).
|
|
||||||
If false is returned the stream had to buffer.
|
|
||||||
|
|
||||||
### "warning"
|
### "warning"
|
||||||
|
|
||||||
`client` will emit `warning` when password was set but none is needed and if a deprecated option / function / similar is used.
|
`client` will emit `warning` when password was set but none is needed and if a deprecated option / function / similar is used.
|
||||||
@@ -260,13 +249,6 @@ NOTE: Your call to `client.auth()` should not be inside the ready handler. If
|
|||||||
you are doing this wrong, `client` will emit an error that looks
|
you are doing this wrong, `client` will emit an error that looks
|
||||||
something like this `Error: Ready check failed: ERR operation not permitted`.
|
something like this `Error: Ready check failed: ERR operation not permitted`.
|
||||||
|
|
||||||
## backpressure
|
|
||||||
|
|
||||||
### stream
|
|
||||||
|
|
||||||
The client exposed the used [stream](https://nodejs.org/api/stream.html) in `client.stream` and if the stream or client had to [buffer](https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback) the command in `client.should_buffer`.
|
|
||||||
In combination this can be used to implement backpressure by checking the buffer state before sending a command and listening to the stream [drain](https://nodejs.org/api/stream.html#stream_event_drain) event.
|
|
||||||
|
|
||||||
## client.quit()
|
## client.quit()
|
||||||
|
|
||||||
This sends the quit command to the redis server and ends cleanly right after all running commands were properly handled.
|
This sends the quit command to the redis server and ends cleanly right after all running commands were properly handled.
|
||||||
|
@@ -1,34 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
var redis = require('../index');
|
|
||||||
var client = redis.createClient();
|
|
||||||
var remaining_ops = 100000;
|
|
||||||
var paused = false;
|
|
||||||
|
|
||||||
function op () {
|
|
||||||
if (remaining_ops <= 0) {
|
|
||||||
console.error('Finished.');
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
remaining_ops--;
|
|
||||||
client.hset('test hash', 'val ' + remaining_ops, remaining_ops);
|
|
||||||
if (client.should_buffer === true) {
|
|
||||||
console.log('Pausing at ' + remaining_ops);
|
|
||||||
paused = true;
|
|
||||||
} else {
|
|
||||||
setTimeout(op, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
client.on('drain', function () {
|
|
||||||
if (paused) {
|
|
||||||
console.log('Resuming at ' + remaining_ops);
|
|
||||||
paused = false;
|
|
||||||
process.nextTick(op);
|
|
||||||
} else {
|
|
||||||
console.log('Got drain while not paused at ' + remaining_ops);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
op();
|
|
25
index.js
25
index.js
@@ -115,19 +115,8 @@ function RedisClient (options, stream) {
|
|||||||
this.create_stream();
|
this.create_stream();
|
||||||
// The listeners will not be attached right away, so let's print the deprecation message while the listener is attached
|
// The listeners will not be attached right away, so let's print the deprecation message while the listener is attached
|
||||||
this.on('newListener', function (event) {
|
this.on('newListener', function (event) {
|
||||||
if (event === 'drain') {
|
if ((event === 'message_buffer' || event === 'pmessage_buffer' || event === 'messageBuffer' || event === 'pmessageBuffer') && !this.buffers && !this.message_buffers) {
|
||||||
this.warn(
|
this.reply_parser.setReturnBuffers(true);
|
||||||
'The drain event listener is deprecated and will be removed in v.3.0.0.\n' +
|
|
||||||
'If you want to keep on listening to this event please listen to the stream drain event directly.'
|
|
||||||
);
|
|
||||||
} else if ((event === 'message_buffer' || event === 'pmessage_buffer' || event === 'messageBuffer' || event === 'pmessageBuffer') && !this.buffers && !this.message_buffers) {
|
|
||||||
if (this.reply_parser.name !== 'javascript') {
|
|
||||||
return this.warn(
|
|
||||||
'You attached the "' + event + '" listener without the returnBuffers option set to true.\n' +
|
|
||||||
'Please use the JavaScript parser or set the returnBuffers option to true to return buffers.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.reply_parser.optionReturnBuffers = true;
|
|
||||||
this.message_buffers = true;
|
this.message_buffers = true;
|
||||||
this.handle_reply = handle_detect_buffers_reply;
|
this.handle_reply = handle_detect_buffers_reply;
|
||||||
}
|
}
|
||||||
@@ -243,10 +232,6 @@ RedisClient.prototype.create_stream = function () {
|
|||||||
self.connection_gone('end');
|
self.connection_gone('end');
|
||||||
});
|
});
|
||||||
|
|
||||||
this.stream.on('drain', function () {
|
|
||||||
self.drain();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fire the command before redis is connected to be sure it's the first fired command
|
// Fire the command before redis is connected to be sure it's the first fired command
|
||||||
if (this.auth_pass !== undefined) {
|
if (this.auth_pass !== undefined) {
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
@@ -479,7 +464,6 @@ RedisClient.prototype.send_offline_queue = function () {
|
|||||||
debug('Sending offline command: ' + command_obj.command);
|
debug('Sending offline command: ' + command_obj.command);
|
||||||
this.internal_send_command(command_obj);
|
this.internal_send_command(command_obj);
|
||||||
}
|
}
|
||||||
this.drain();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var retry_connection = function (self, error) {
|
var retry_connection = function (self, error) {
|
||||||
@@ -612,11 +596,6 @@ RedisClient.prototype.return_error = function (err) {
|
|||||||
utils.callback_or_emit(this, command_obj.callback, err);
|
utils.callback_or_emit(this, command_obj.callback, err);
|
||||||
};
|
};
|
||||||
|
|
||||||
RedisClient.prototype.drain = function () {
|
|
||||||
this.emit('drain');
|
|
||||||
this.should_buffer = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
function normal_reply (self, reply) {
|
function normal_reply (self, reply) {
|
||||||
var command_obj = self.command_queue.shift();
|
var command_obj = self.command_queue.shift();
|
||||||
if (typeof command_obj.callback === 'function') {
|
if (typeof command_obj.callback === 'function') {
|
||||||
|
@@ -952,28 +952,6 @@ describe('The node_redis client', function () {
|
|||||||
|
|
||||||
describe('enable_offline_queue', function () {
|
describe('enable_offline_queue', function () {
|
||||||
describe('true', function () {
|
describe('true', function () {
|
||||||
it('should emit drain if offline queue is flushed and nothing to buffer', function (done) {
|
|
||||||
client = redis.createClient({
|
|
||||||
parser: parser,
|
|
||||||
no_ready_check: true
|
|
||||||
});
|
|
||||||
var end = helper.callFuncAfter(done, 3);
|
|
||||||
client.set('foo', 'bar');
|
|
||||||
client.get('foo', end);
|
|
||||||
client.on('warning', function (msg) {
|
|
||||||
assert.strictEqual(
|
|
||||||
msg,
|
|
||||||
'The drain event listener is deprecated and will be removed in v.3.0.0.\n' +
|
|
||||||
'If you want to keep on listening to this event please listen to the stream drain event directly.'
|
|
||||||
);
|
|
||||||
end();
|
|
||||||
});
|
|
||||||
client.on('drain', function () {
|
|
||||||
assert(client.offline_queue.length === 0);
|
|
||||||
end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not return an error and enqueues operation', function (done) {
|
it('does not return an error and enqueues operation', function (done) {
|
||||||
client = redis.createClient(9999, null, {
|
client = redis.createClient(9999, null, {
|
||||||
parser: parser
|
parser: parser
|
||||||
|
Reference in New Issue
Block a user