diff --git a/README.md b/README.md index 269ed19aa6..84253fe0d6 100644 --- a/README.md +++ b/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. -### "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" `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 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() This sends the quit command to the redis server and ends cleanly right after all running commands were properly handled. diff --git a/examples/backpressure_drain.js b/examples/backpressure_drain.js deleted file mode 100644 index 0e9140c6b2..0000000000 --- a/examples/backpressure_drain.js +++ /dev/null @@ -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(); diff --git a/index.js b/index.js index 1f83c3f585..f8a27f67a7 100644 --- a/index.js +++ b/index.js @@ -115,19 +115,8 @@ function RedisClient (options, stream) { this.create_stream(); // 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) { - if (event === 'drain') { - this.warn( - '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; + if ((event === 'message_buffer' || event === 'pmessage_buffer' || event === 'messageBuffer' || event === 'pmessageBuffer') && !this.buffers && !this.message_buffers) { + this.reply_parser.setReturnBuffers(true); this.message_buffers = true; this.handle_reply = handle_detect_buffers_reply; } @@ -243,10 +232,6 @@ RedisClient.prototype.create_stream = function () { 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 if (this.auth_pass !== undefined) { this.ready = true; @@ -479,7 +464,6 @@ RedisClient.prototype.send_offline_queue = function () { debug('Sending offline command: ' + command_obj.command); this.internal_send_command(command_obj); } - this.drain(); }; 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); }; -RedisClient.prototype.drain = function () { - this.emit('drain'); - this.should_buffer = false; -}; - function normal_reply (self, reply) { var command_obj = self.command_queue.shift(); if (typeof command_obj.callback === 'function') { diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index 4ba75c0e82..e5b6436d73 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -952,28 +952,6 @@ describe('The node_redis client', function () { describe('enable_offline_queue', 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) { client = redis.createClient(9999, null, { parser: parser