File tree Expand file tree Collapse file tree 5 files changed +48
-6
lines changed Expand file tree Collapse file tree 5 files changed +48
-6
lines changed Original file line number Diff line number Diff line change @@ -212,11 +212,13 @@ NOTE: Your call to `client.auth()` should not be inside the ready handler. If
212212you are doing this wrong, ` client ` will emit an error that looks
213213something like this ` Error: Ready check failed: ERR operation not permitted ` .
214214
215- ## client.end()
215+ ## client.end([ flush ] )
216216
217217Forcibly close the connection to the Redis server. Note that this does not wait until all replies have been parsed.
218218If you want to exit cleanly, call ` client.quit() ` to send the ` QUIT ` command after you have handled all replies.
219219
220+ If flush is set to true, all commands will be rejected instead of ignored after using ` .end ` .
221+
220222This example closes the connection to the Redis server before the replies have been read. You probably don't
221223want to do this:
222224
@@ -227,7 +229,7 @@ var redis = require("redis"),
227229client .set (" foo_rand000000000000" , " some fantastic value" );
228230client .end (); // No further commands will be processed
229231client .get (" foo_rand000000000000" , function (err , reply ) {
230- // This won't be called anymore
232+ // This won't be called anymore, since flush has not been set to true!
231233 console .log (err);
232234});
233235```
Original file line number Diff line number Diff line change 11Changelog
22=========
33
4- ## v2.x.x - xx, 2015
4+ ## v2.1.0 - xx, 2015
5+
6+ Features:
7+
8+ - Add optional flush parameter to ` .end ` . If set to true, commands fired after using .end are going to be rejected instead of being ignored. (@crispy1989 )
59
610Bugfixes:
711
Original file line number Diff line number Diff line change @@ -838,7 +838,7 @@ RedisClient.prototype.pub_sub_command = function (command_obj) {
838838 }
839839} ;
840840
841- RedisClient . prototype . end = function ( ) {
841+ RedisClient . prototype . end = function ( flush ) {
842842 this . stream . _events = { } ;
843843
844844 // Clear retry_timer
@@ -848,8 +848,10 @@ RedisClient.prototype.end = function () {
848848 }
849849 this . stream . on ( "error" , function noop ( ) { } ) ;
850850
851- // Flush queue
852- this . flush_and_error ( "Redis connection ended." ) ;
851+ // Flush queue if wanted
852+ if ( flush ) {
853+ this . flush_and_error ( "Redis connection ended." ) ;
854+ }
853855
854856 this . connected = false ;
855857 this . ready = false ;
Original file line number Diff line number Diff line change @@ -196,6 +196,14 @@ describe("The 'multi' method", function () {
196196 } ) . exec ( done ) ;
197197 } ) ;
198198
199+ it ( 'runs a multi without any further commands' , function ( done ) {
200+ client . multi ( ) . exec ( function ( err , res ) {
201+ assert . strictEqual ( err , null ) ;
202+ assert . strictEqual ( res . length , 0 ) ;
203+ done ( ) ;
204+ } ) ;
205+ } ) ;
206+
199207 it ( 'allows multiple operations to be performed using a chaining API' , function ( done ) {
200208 client . multi ( )
201209 . mset ( 'some' , '10' , 'keys' , '20' )
Original file line number Diff line number Diff line change @@ -174,6 +174,32 @@ describe("The node_redis client", function () {
174174
175175 } ) ;
176176
177+ describe ( ".end" , function ( ) {
178+
179+ it ( 'used without flush' , function ( done ) {
180+ var err = null ;
181+ client . set ( 'foo' , 'bar' ) ;
182+ client . end ( ) ;
183+ client . get ( 'foo' , function ( err , res ) {
184+ err = new Error ( 'failed' ) ;
185+ } ) ;
186+ setTimeout ( function ( ) {
187+ done ( err ) ;
188+ } , 200 ) ;
189+ } ) ;
190+
191+ it ( 'used with flush set to true' , function ( done ) {
192+ client . set ( 'foo' , 'bar' ) ;
193+ client . end ( ) ;
194+ client . get ( 'foo' , function ( err , res ) {
195+ assert . strictEqual ( err . command , 'GET' ) ;
196+ assert . strictEqual ( err . message , "GET can't be processed. The connection has already been closed." ) ;
197+ done ( ) ;
198+ } ) ;
199+ } ) ;
200+
201+ } ) ;
202+
177203 describe ( "commands after using .quit should fail" , function ( ) {
178204
179205 it ( "return an error in the callback" , function ( done ) {
You can’t perform that action at this time.
0 commit comments