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
212
212
you are doing this wrong, ` client ` will emit an error that looks
213
213
something like this ` Error: Ready check failed: ERR operation not permitted ` .
214
214
215
- ## client.end()
215
+ ## client.end([ flush ] )
216
216
217
217
Forcibly close the connection to the Redis server. Note that this does not wait until all replies have been parsed.
218
218
If you want to exit cleanly, call ` client.quit() ` to send the ` QUIT ` command after you have handled all replies.
219
219
220
+ If flush is set to true, all commands will be rejected instead of ignored after using ` .end ` .
221
+
220
222
This example closes the connection to the Redis server before the replies have been read. You probably don't
221
223
want to do this:
222
224
@@ -227,7 +229,7 @@ var redis = require("redis"),
227
229
client .set (" foo_rand000000000000" , " some fantastic value" );
228
230
client .end (); // No further commands will be processed
229
231
client .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!
231
233
console .log (err);
232
234
});
233
235
```
Original file line number Diff line number Diff line change 1
1
Changelog
2
2
=========
3
3
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 )
5
9
6
10
Bugfixes:
7
11
Original file line number Diff line number Diff line change @@ -838,7 +838,7 @@ RedisClient.prototype.pub_sub_command = function (command_obj) {
838
838
}
839
839
} ;
840
840
841
- RedisClient . prototype . end = function ( ) {
841
+ RedisClient . prototype . end = function ( flush ) {
842
842
this . stream . _events = { } ;
843
843
844
844
// Clear retry_timer
@@ -848,8 +848,10 @@ RedisClient.prototype.end = function () {
848
848
}
849
849
this . stream . on ( "error" , function noop ( ) { } ) ;
850
850
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
+ }
853
855
854
856
this . connected = false ;
855
857
this . ready = false ;
Original file line number Diff line number Diff line change @@ -196,6 +196,14 @@ describe("The 'multi' method", function () {
196
196
} ) . exec ( done ) ;
197
197
} ) ;
198
198
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
+
199
207
it ( 'allows multiple operations to be performed using a chaining API' , function ( done ) {
200
208
client . multi ( )
201
209
. 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 () {
174
174
175
175
} ) ;
176
176
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
+
177
203
describe ( "commands after using .quit should fail" , function ( ) {
178
204
179
205
it ( "return an error in the callback" , function ( done ) {
You can’t perform that action at this time.
0 commit comments