@@ -28,7 +28,7 @@ class ConnectionTest extends TestCase
28
28
public static function setUpBeforeClass (): void
29
29
{
30
30
try {
31
- $ redis = Connection::fromDsn ('redis://localhost/queue ' );
31
+ $ redis = Connection::fromDsn ('redis://localhost/queue?delete_after_ack=true ' );
32
32
$ redis ->get ();
33
33
} catch (TransportException $ e ) {
34
34
if (0 === strpos ($ e ->getMessage (), 'ERR unknown command \'X ' )) {
@@ -61,11 +61,11 @@ public function testFromInvalidDsn()
61
61
public function testFromDsn ()
62
62
{
63
63
$ this ->assertEquals (
64
- new Connection (['stream ' => 'queue ' ], [
64
+ new Connection (['stream ' => 'queue ' , ' delete_after_ack ' => true ], [
65
65
'host ' => 'localhost ' ,
66
66
'port ' => 6379 ,
67
67
]),
68
- Connection::fromDsn ('redis://localhost/queue ' )
68
+ Connection::fromDsn ('redis://localhost/queue?delete_after_ack=1 ' )
69
69
);
70
70
}
71
71
@@ -80,33 +80,33 @@ public function testFromDsnWithMultipleHosts()
80
80
}, $ hosts );
81
81
$ dsn = implode (', ' , $ dsn );
82
82
83
- $ this ->assertInstanceOf (Connection::class, Connection::fromDsn ($ dsn ));
83
+ $ this ->assertInstanceOf (Connection::class, Connection::fromDsn ($ dsn, [ ' delete_after_ack ' => true ] ));
84
84
}
85
85
86
86
public function testFromDsnOnUnixSocket ()
87
87
{
88
88
$ this ->assertEquals (
89
- new Connection (['stream ' => 'queue ' ], [
89
+ new Connection (['stream ' => 'queue ' , ' delete_after_ack ' => true ], [
90
90
'host ' => '/var/run/redis/redis.sock ' ,
91
91
'port ' => 0 ,
92
92
], [], $ redis = $ this ->createMock (\Redis::class)),
93
- Connection::fromDsn ('redis:///var/run/redis/redis.sock ' , ['stream ' => 'queue ' ], $ redis )
93
+ Connection::fromDsn ('redis:///var/run/redis/redis.sock ' , ['stream ' => 'queue ' , ' delete_after_ack ' => true ], $ redis )
94
94
);
95
95
}
96
96
97
97
public function testFromDsnWithOptions ()
98
98
{
99
99
$ this ->assertEquals (
100
- Connection::fromDsn ('redis://localhost ' , ['stream ' => 'queue ' , 'group ' => 'group1 ' , 'consumer ' => 'consumer1 ' , 'auto_setup ' => false , 'serializer ' => 2 ]),
101
- Connection::fromDsn ('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0 ' )
100
+ Connection::fromDsn ('redis://localhost ' , ['stream ' => 'queue ' , 'group ' => 'group1 ' , 'consumer ' => 'consumer1 ' , 'auto_setup ' => false , 'serializer ' => 2 , ' delete_after_ack ' => true ]),
101
+ Connection::fromDsn ('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0&delete_after_ack=1 ' )
102
102
);
103
103
}
104
104
105
105
public function testFromDsnWithOptionsAndTrailingSlash ()
106
106
{
107
107
$ this ->assertEquals (
108
- Connection::fromDsn ('redis://localhost/ ' , ['stream ' => 'queue ' , 'group ' => 'group1 ' , 'consumer ' => 'consumer1 ' , 'auto_setup ' => false , 'serializer ' => 2 ]),
109
- Connection::fromDsn ('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0 ' )
108
+ Connection::fromDsn ('redis://localhost/ ' , ['stream ' => 'queue ' , 'group ' => 'group1 ' , 'consumer ' => 'consumer1 ' , 'auto_setup ' => false , 'serializer ' => 2 , ' delete_after_ack ' => true ]),
109
+ Connection::fromDsn ('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0&delete_after_ack=1 ' )
110
110
);
111
111
}
112
112
@@ -146,32 +146,32 @@ public function testFromDsnWithRedissScheme()
146
146
->with ('tls://127.0.0.1 ' , 6379 )
147
147
->willReturn (null );
148
148
149
- Connection::fromDsn ('rediss://127.0.0.1 ' , [], $ redis );
149
+ Connection::fromDsn ('rediss://127.0.0.1?delete_after_ack=true ' , [], $ redis );
150
150
}
151
151
152
152
public function testFromDsnWithQueryOptions ()
153
153
{
154
154
$ this ->assertEquals (
155
- new Connection (['stream ' => 'queue ' , 'group ' => 'group1 ' , 'consumer ' => 'consumer1 ' ], [
155
+ new Connection (['stream ' => 'queue ' , 'group ' => 'group1 ' , 'consumer ' => 'consumer1 ' , ' delete_after_ack ' => true ], [
156
156
'host ' => 'localhost ' ,
157
157
'port ' => 6379 ,
158
158
], [
159
159
'serializer ' => 2 ,
160
160
]),
161
- Connection::fromDsn ('redis://localhost/queue/group1/consumer1?serializer=2 ' )
161
+ Connection::fromDsn ('redis://localhost/queue/group1/consumer1?serializer=2&delete_after_ack=1 ' )
162
162
);
163
163
}
164
164
165
165
public function testFromDsnWithMixDsnQueryOptions ()
166
166
{
167
167
$ this ->assertEquals (
168
- Connection::fromDsn ('redis://localhost/queue/group1?serializer=2 ' , ['consumer ' => 'specific-consumer ' ]),
169
- Connection::fromDsn ('redis://localhost/queue/group1/specific-consumer?serializer=2 ' )
168
+ Connection::fromDsn ('redis://localhost/queue/group1?serializer=2 ' , ['consumer ' => 'specific-consumer ' , ' delete_after_ack ' => true ]),
169
+ Connection::fromDsn ('redis://localhost/queue/group1/specific-consumer?serializer=2&delete_after_ack=1 ' )
170
170
);
171
171
172
172
$ this ->assertEquals (
173
- Connection::fromDsn ('redis://localhost/queue/group1/consumer1 ' , ['consumer ' => 'specific-consumer ' ]),
174
- Connection::fromDsn ('redis://localhost/queue/group1/consumer1 ' )
173
+ Connection::fromDsn ('redis://localhost/queue/group1/consumer1 ' , ['consumer ' => 'specific-consumer ' , ' delete_after_ack ' => true ]),
174
+ Connection::fromDsn ('redis://localhost/queue/group1/consumer1?delete_after_ack=1 ' )
175
175
);
176
176
}
177
177
@@ -200,7 +200,7 @@ public function testKeepGettingPendingMessages()
200
200
->with ('symfony ' , 'consumer ' , ['queue ' => 0 ], 1 , null )
201
201
->willReturn (['queue ' => [['message ' => '{"body":"Test","headers":[]} ' ]]]);
202
202
203
- $ connection = Connection::fromDsn ('redis://localhost/queue ' , [], $ redis );
203
+ $ connection = Connection::fromDsn ('redis://localhost/queue ' , [' delete_after_ack ' => true ], $ redis );
204
204
$ this ->assertNotNull ($ connection ->get ());
205
205
$ this ->assertNotNull ($ connection ->get ());
206
206
$ this ->assertNotNull ($ connection ->get ());
@@ -214,7 +214,7 @@ public function testAuth()
214
214
->with ('password ' )
215
215
->willReturn (true );
216
216
217
- Connection::fromDsn ('redis://password@localhost/queue ' , [], $ redis );
217
+ Connection::fromDsn ('redis://password@localhost/queue ' , [' delete_after_ack ' => true ], $ redis );
218
218
}
219
219
220
220
public function testAuthFromOptions ()
@@ -225,7 +225,7 @@ public function testAuthFromOptions()
225
225
->with ('password ' )
226
226
->willReturn (true );
227
227
228
- Connection::fromDsn ('redis://localhost/queue ' , ['auth ' => 'password ' ], $ redis );
228
+ Connection::fromDsn ('redis://localhost/queue ' , ['auth ' => 'password ' , ' delete_after_ack ' => true ], $ redis );
229
229
}
230
230
231
231
public function testAuthFromOptionsAndDsn ()
@@ -236,7 +236,7 @@ public function testAuthFromOptionsAndDsn()
236
236
->with ('password2 ' )
237
237
->willReturn (true );
238
238
239
- Connection::fromDsn ('redis://password1@localhost/queue ' , ['auth ' => 'password2 ' ], $ redis );
239
+ Connection::fromDsn ('redis://password1@localhost/queue ' , ['auth ' => 'password2 ' , ' delete_after_ack ' => true ], $ redis );
240
240
}
241
241
242
242
public function testNoAuthWithEmptyPassword ()
@@ -247,7 +247,7 @@ public function testNoAuthWithEmptyPassword()
247
247
->with ('' )
248
248
->willThrowException (new \RuntimeException ());
249
249
250
- Connection::fromDsn ('redis://@localhost/queue ' , [], $ redis );
250
+ Connection::fromDsn ('redis://@localhost/queue ' , [' delete_after_ack ' => true ], $ redis );
251
251
}
252
252
253
253
public function testAuthZeroPassword ()
@@ -258,7 +258,7 @@ public function testAuthZeroPassword()
258
258
->with ('0 ' )
259
259
->willReturn (true );
260
260
261
- Connection::fromDsn ('redis://0@localhost/queue ' , [], $ redis );
261
+ Connection::fromDsn ('redis://0@localhost/queue ' , [' delete_after_ack ' => true ], $ redis );
262
262
}
263
263
264
264
public function testFailedAuth ()
@@ -271,14 +271,14 @@ public function testFailedAuth()
271
271
->with ('password ' )
272
272
->willReturn (false );
273
273
274
- Connection::fromDsn ('redis://password@localhost/queue ' , [], $ redis );
274
+ Connection::fromDsn ('redis://password@localhost/queue ' , [' delete_after_ack ' => true ], $ redis );
275
275
}
276
276
277
277
public function testDbIndex ()
278
278
{
279
279
$ redis = new \Redis ();
280
280
281
- Connection::fromDsn ('redis://localhost/queue?dbindex=2 ' , [], $ redis );
281
+ Connection::fromDsn ('redis://localhost/queue?dbindex=2 ' , [' delete_after_ack ' => true ], $ redis );
282
282
283
283
$ this ->assertSame (2 , $ redis ->getDbNum ());
284
284
}
@@ -291,7 +291,7 @@ public function testGetPendingMessageFirst()
291
291
->with ('symfony ' , 'consumer ' , ['queue ' => '0 ' ], 1 , null )
292
292
->willReturn (['queue ' => [['message ' => '{"body":"1","headers":[]} ' ]]]);
293
293
294
- $ connection = Connection::fromDsn ('redis://localhost/queue ' , [], $ redis );
294
+ $ connection = Connection::fromDsn ('redis://localhost/queue ' , [' delete_after_ack ' => true ], $ redis );
295
295
$ connection ->get ();
296
296
}
297
297
@@ -317,7 +317,7 @@ public function testClaimAbandonedMessageWithRaceCondition()
317
317
->with ('queue ' , 'symfony ' , 'consumer ' , 3600000 , ['redisid-123 ' ], ['JUSTID ' ])
318
318
->willReturn ([]);
319
319
320
- $ connection = Connection::fromDsn ('redis://localhost/queue ' , [], $ redis );
320
+ $ connection = Connection::fromDsn ('redis://localhost/queue ' , [' delete_after_ack ' => true ], $ redis );
321
321
$ connection ->get ();
322
322
}
323
323
@@ -345,7 +345,7 @@ public function testClaimAbandonedMessage()
345
345
->with ('queue ' , 'symfony ' , 'consumer ' , 3600000 , ['redisid-123 ' ], ['JUSTID ' ])
346
346
->willReturn ([]);
347
347
348
- $ connection = Connection::fromDsn ('redis://localhost/queue ' , [], $ redis );
348
+ $ connection = Connection::fromDsn ('redis://localhost/queue ' , [' delete_after_ack ' => true ], $ redis );
349
349
$ connection ->get ();
350
350
}
351
351
@@ -357,22 +357,22 @@ public function testUnexpectedRedisError()
357
357
$ redis ->expects ($ this ->once ())->method ('xreadgroup ' )->willReturn (false );
358
358
$ redis ->expects ($ this ->once ())->method ('getLastError ' )->willReturn ('Redis error happens ' );
359
359
360
- $ connection = Connection::fromDsn ('redis://localhost/queue ' , ['auto_setup ' => false ], $ redis );
360
+ $ connection = Connection::fromDsn ('redis://localhost/queue ' , ['auto_setup ' => false , ' delete_after_ack ' => true ], $ redis );
361
361
$ connection ->get ();
362
362
}
363
363
364
364
public function testGetAfterReject ()
365
365
{
366
366
$ redis = new \Redis ();
367
- $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , [], $ redis );
367
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , [' delete_after_ack ' => true ], $ redis );
368
368
369
369
$ connection ->add ('1 ' , []);
370
370
$ connection ->add ('2 ' , []);
371
371
372
372
$ failing = $ connection ->get ();
373
373
$ connection ->reject ($ failing ['id ' ]);
374
374
375
- $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' );
375
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , [ ' delete_after_ack ' => true ] );
376
376
$ this ->assertNotNull ($ connection ->get ());
377
377
378
378
$ redis ->del ('messenger-rejectthenget ' );
@@ -382,7 +382,7 @@ public function testGetNonBlocking()
382
382
{
383
383
$ redis = new \Redis ();
384
384
385
- $ connection = Connection::fromDsn ('redis://localhost/messenger-getnonblocking ' , [], $ redis );
385
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-getnonblocking ' , [' delete_after_ack ' => true ], $ redis );
386
386
387
387
$ this ->assertNull ($ connection ->get ()); // no message, should return null immediately
388
388
$ connection ->add ('1 ' , []);
@@ -394,7 +394,7 @@ public function testGetNonBlocking()
394
394
public function testJsonError ()
395
395
{
396
396
$ redis = new \Redis ();
397
- $ connection = Connection::fromDsn ('redis://localhost/json-error ' , [], $ redis );
397
+ $ connection = Connection::fromDsn ('redis://localhost/json-error ' , [' delete_after_ack ' => true ], $ redis );
398
398
try {
399
399
$ connection ->add ("\xB1\x31" , []);
400
400
} catch (TransportException $ e ) {
@@ -411,7 +411,7 @@ public function testMaxEntries()
411
411
->with ('queue ' , '* ' , ['message ' => '{"body":"1","headers":[]} ' ], 20000 , true )
412
412
->willReturn (1 );
413
413
414
- $ connection = Connection::fromDsn ('redis://localhost/queue?stream_max_entries=20000 ' , [], $ redis ); // 1 = always
414
+ $ connection = Connection::fromDsn ('redis://localhost/queue?stream_max_entries=20000 ' , [' delete_after_ack ' => true ], $ redis );
415
415
$ connection ->add ('1 ' , []);
416
416
}
417
417
@@ -426,10 +426,20 @@ public function testDeleteAfterAck()
426
426
->with ('queue ' , ['1 ' ])
427
427
->willReturn (1 );
428
428
429
- $ connection = Connection::fromDsn ('redis://localhost/queue?delete_after_ack=true ' , [], $ redis ); // 1 = always
429
+ $ connection = Connection::fromDsn ('redis://localhost/queue?delete_after_ack=true ' , [], $ redis );
430
430
$ connection ->ack ('1 ' );
431
431
}
432
432
433
+ /**
434
+ * @group legacy
435
+ */
436
+ public function testLegacyOmitDeleteAfterAck ()
437
+ {
438
+ $ this ->expectDeprecation ('Since symfony/redis-messenger 5.4: Not setting the "delete_after_ack" boolean option explicitly is deprecated, its default value will change to true in 6.0. ' );
439
+
440
+ Connection::fromDsn ('redis://localhost/queue ' );
441
+ }
442
+
433
443
public function testDeleteAfterReject ()
434
444
{
435
445
$ redis = $ this ->createMock (\Redis::class);
@@ -441,7 +451,7 @@ public function testDeleteAfterReject()
441
451
->with ('queue ' , ['1 ' ])
442
452
->willReturn (1 );
443
453
444
- $ connection = Connection::fromDsn ('redis://localhost/queue?delete_after_reject=true ' , [], $ redis ); // 1 = always
454
+ $ connection = Connection::fromDsn ('redis://localhost/queue?delete_after_reject=true ' , [' delete_after_ack ' => true ], $ redis );
445
455
$ connection ->reject ('1 ' );
446
456
}
447
457
@@ -455,7 +465,7 @@ public function testLastErrorGetsCleared()
455
465
$ redis ->method ('getLastError ' )->willReturnOnConsecutiveCalls ('xadd error ' , 'xack error ' );
456
466
$ redis ->expects ($ this ->exactly (2 ))->method ('clearLastError ' );
457
467
458
- $ connection = Connection::fromDsn ('redis://localhost/messenger-clearlasterror ' , ['auto_setup ' => false ], $ redis );
468
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-clearlasterror ' , ['auto_setup ' => false , ' delete_after_ack ' => true ], $ redis );
459
469
460
470
try {
461
471
$ connection ->add ('message ' , []);
@@ -475,7 +485,7 @@ public function testLastErrorGetsCleared()
475
485
public function testLazy ()
476
486
{
477
487
$ redis = new \Redis ();
478
- $ connection = Connection::fromDsn ('redis://localhost/messenger-lazy?lazy=1 ' , [], $ redis );
488
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-lazy?lazy=1 ' , [' delete_after_ack ' => true ], $ redis );
479
489
480
490
$ connection ->add ('1 ' , []);
481
491
$ this ->assertNotEmpty ($ message = $ connection ->get ());
@@ -490,7 +500,8 @@ public function testLazyCluster()
490
500
491
501
$ connection = new Connection (
492
502
['lazy ' => true ],
493
- ['host ' => explode (' ' , getenv ('REDIS_CLUSTER_HOSTS ' ))]
503
+ ['host ' => explode (' ' , getenv ('REDIS_CLUSTER_HOSTS ' ))],
504
+ ['delete_after_ack ' => true ]
494
505
);
495
506
496
507
$ connection ->add ('1 ' , []);
0 commit comments