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