@@ -34,7 +34,7 @@ protected function setUp(): void
34
34
35
35
try {
36
36
$ this ->redis = new \Redis ();
37
- $ this ->connection = Connection::fromDsn (getenv ('MESSENGER_REDIS_DSN ' ), ['delete_after_ack ' => true ], $ this ->redis );
37
+ $ this ->connection = Connection::fromDsn (getenv ('MESSENGER_REDIS_DSN ' ), ['delete_after_ack ' => true , ' sentinel_master ' => getenv ( ' MESSENGER_REDIS_SENTINEL_MASTER ' ) ], $ this ->redis );
38
38
$ this ->connection ->cleanup ();
39
39
$ this ->connection ->setup ();
40
40
} catch (\Exception $ e ) {
@@ -142,8 +142,7 @@ public function testConnectionSendDelayedMessagesWithSameContent()
142
142
public function testConnectionBelowRedeliverTimeout ()
143
143
{
144
144
// lower redeliver timeout and claim interval
145
- $ connection = Connection::fromDsn (getenv ('MESSENGER_REDIS_DSN ' ), ['delete_after_ack ' => true ], $ this ->redis );
146
-
145
+ $ connection = Connection::fromDsn (getenv ('MESSENGER_REDIS_DSN ' ), ['delete_after_ack ' => true , 'sentinel_master ' => getenv ('MESSENGER_REDIS_SENTINEL_MASTER ' )], $ this ->redis );
147
146
$ connection ->cleanup ();
148
147
$ connection ->setup ();
149
148
@@ -170,7 +169,7 @@ public function testConnectionClaimAndRedeliver()
170
169
// lower redeliver timeout and claim interval
171
170
$ connection = Connection::fromDsn (
172
171
getenv ('MESSENGER_REDIS_DSN ' ),
173
- ['redeliver_timeout ' => 0 , 'claim_interval ' => 500 , 'delete_after_ack ' => true ],
172
+ ['redeliver_timeout ' => 0 , 'claim_interval ' => 500 , 'delete_after_ack ' => true , ' sentinel_master ' => getenv ( ' MESSENGER_REDIS_SENTINEL_MASTER ' ) ],
174
173
$ this ->redis
175
174
);
176
175
@@ -214,6 +213,25 @@ public function testConnectionClaimAndRedeliver()
214
213
$ connection ->ack ($ message ['id ' ]);
215
214
}
216
215
216
+ public function testLazySentinel ()
217
+ {
218
+ $ connection = Connection::fromDsn (getenv ('MESSENGER_REDIS_DSN ' ),
219
+ ['lazy ' => true ,
220
+ 'delete_after_ack ' => true ,
221
+ 'sentinel_master ' => getenv ('MESSENGER_REDIS_SENTINEL_MASTER ' ), ], $ this ->redis );
222
+
223
+ $ connection ->add ('1 ' , []);
224
+ $ this ->assertNotEmpty ($ message = $ connection ->get ());
225
+ $ this ->assertSame ([
226
+ 'message ' => json_encode ([
227
+ 'body ' => '1 ' ,
228
+ 'headers ' => [],
229
+ ]),
230
+ ], $ message ['data ' ]);
231
+ $ connection ->reject ($ message ['id ' ]);
232
+ $ connection ->cleanup ();
233
+ }
234
+
217
235
public function testLazyCluster ()
218
236
{
219
237
$ this ->skipIfRedisClusterUnavailable ();
@@ -273,7 +291,7 @@ public function testFromDsnWithMultipleHosts()
273
291
}, $ hosts );
274
292
$ dsn = implode (', ' , $ dsn );
275
293
276
- $ this ->assertInstanceOf (Connection::class, Connection::fromDsn ($ dsn , ['delete_after_ack ' => true ]));
294
+ $ this ->assertInstanceOf (Connection::class, Connection::fromDsn ($ dsn , ['delete_after_ack ' => true , ' sentinel_master ' => getenv ( ' MESSENGER_REDIS_SENTINEL_MASTER ' ) ]));
277
295
}
278
296
279
297
public function testJsonError ()
@@ -292,7 +310,7 @@ public function testGetNonBlocking()
292
310
{
293
311
$ redis = new \Redis ();
294
312
295
- $ connection = Connection::fromDsn ('redis://localhost/messenger-getnonblocking ' , ['delete_after_ack ' => true ], $ redis );
313
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-getnonblocking ' , ['delete_after_ack ' => true , ' sentinel_master ' => null ], $ redis );
296
314
297
315
$ this ->assertNull ($ connection ->get ()); // no message, should return null immediately
298
316
$ connection ->add ('1 ' , []);
@@ -304,15 +322,15 @@ public function testGetNonBlocking()
304
322
public function testGetAfterReject ()
305
323
{
306
324
$ redis = new \Redis ();
307
- $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , ['delete_after_ack ' => true ], $ redis );
325
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , ['delete_after_ack ' => true , ' sentinel_master ' => null ], $ redis );
308
326
309
327
$ connection ->add ('1 ' , []);
310
328
$ connection ->add ('2 ' , []);
311
329
312
330
$ failing = $ connection ->get ();
313
331
$ connection ->reject ($ failing ['id ' ]);
314
332
315
- $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , ['delete_after_ack ' => true ]);
333
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , ['delete_after_ack ' => true , ' sentinel_master ' => null ]);
316
334
$ this ->assertNotNull ($ connection ->get ());
317
335
318
336
$ redis ->del ('messenger-rejectthenget ' );
0 commit comments