@@ -283,7 +283,10 @@ public static function createConnection(string $dsn, array $options = [])
283
283
}
284
284
285
285
if ((null !== $ auth && !$ redis ->auth ($ auth ))
286
- || ($ params ['dbindex ' ] && !$ redis ->select ($ params ['dbindex ' ]))
286
+ // Due to a bug in phpredis we must always select the dbindex if persistent pooling is enabled
287
+ // @see https://github.com/phpredis/phpredis/issues/1920
288
+ // @see https://github.com/symfony/symfony/issues/51578
289
+ || (($ params ['dbindex ' ] || ('pconnect ' === $ connect && '0 ' !== \ini_get ('redis.pconnect.pooling_enabled ' ))) && !$ redis ->select ($ params ['dbindex ' ]))
287
290
) {
288
291
$ e = preg_replace ('/^ERR / ' , '' , $ redis ->getLastError ());
289
292
throw new InvalidArgumentException ('Redis connection failed: ' .$ e .'. ' );
@@ -307,8 +310,10 @@ public static function createConnection(string $dsn, array $options = [])
307
310
} elseif (is_a ($ class , \RedisArray::class, true )) {
308
311
foreach ($ hosts as $ i => $ host ) {
309
312
switch ($ host ['scheme ' ]) {
310
- case 'tcp ' : $ hosts [$ i ] = $ host ['host ' ].': ' .$ host ['port ' ]; break ;
311
- case 'tls ' : $ hosts [$ i ] = 'tls:// ' .$ host ['host ' ].': ' .$ host ['port ' ]; break ;
313
+ case 'tcp ' : $ hosts [$ i ] = $ host ['host ' ].': ' .$ host ['port ' ];
314
+ break ;
315
+ case 'tls ' : $ hosts [$ i ] = 'tls:// ' .$ host ['host ' ].': ' .$ host ['port ' ];
316
+ break ;
312
317
default : $ hosts [$ i ] = $ host ['path ' ];
313
318
}
314
319
}
@@ -328,8 +333,10 @@ public static function createConnection(string $dsn, array $options = [])
328
333
$ initializer = static function () use ($ class , $ params , $ hosts ) {
329
334
foreach ($ hosts as $ i => $ host ) {
330
335
switch ($ host ['scheme ' ]) {
331
- case 'tcp ' : $ hosts [$ i ] = $ host ['host ' ].': ' .$ host ['port ' ]; break ;
332
- case 'tls ' : $ hosts [$ i ] = 'tls:// ' .$ host ['host ' ].': ' .$ host ['port ' ]; break ;
336
+ case 'tcp ' : $ hosts [$ i ] = $ host ['host ' ].': ' .$ host ['port ' ];
337
+ break ;
338
+ case 'tls ' : $ hosts [$ i ] = 'tls:// ' .$ host ['host ' ].': ' .$ host ['port ' ];
339
+ break ;
333
340
default : $ hosts [$ i ] = $ host ['path ' ];
334
341
}
335
342
}
@@ -344,9 +351,12 @@ public static function createConnection(string $dsn, array $options = [])
344
351
$ redis ->setOption (\Redis::OPT_TCP_KEEPALIVE , $ params ['tcp_keepalive ' ]);
345
352
}
346
353
switch ($ params ['failover ' ]) {
347
- case 'error ' : $ redis ->setOption (\RedisCluster::OPT_SLAVE_FAILOVER , \RedisCluster::FAILOVER_ERROR ); break ;
348
- case 'distribute ' : $ redis ->setOption (\RedisCluster::OPT_SLAVE_FAILOVER , \RedisCluster::FAILOVER_DISTRIBUTE ); break ;
349
- case 'slaves ' : $ redis ->setOption (\RedisCluster::OPT_SLAVE_FAILOVER , \RedisCluster::FAILOVER_DISTRIBUTE_SLAVES ); break ;
354
+ case 'error ' : $ redis ->setOption (\RedisCluster::OPT_SLAVE_FAILOVER , \RedisCluster::FAILOVER_ERROR );
355
+ break ;
356
+ case 'distribute ' : $ redis ->setOption (\RedisCluster::OPT_SLAVE_FAILOVER , \RedisCluster::FAILOVER_DISTRIBUTE );
357
+ break ;
358
+ case 'slaves ' : $ redis ->setOption (\RedisCluster::OPT_SLAVE_FAILOVER , \RedisCluster::FAILOVER_DISTRIBUTE_SLAVES );
359
+ break ;
350
360
}
351
361
352
362
return $ redis ;
@@ -403,9 +413,6 @@ public static function createConnection(string $dsn, array $options = [])
403
413
return $ redis ;
404
414
}
405
415
406
- /**
407
- * {@inheritdoc}
408
- */
409
416
protected function doFetch (array $ ids )
410
417
{
411
418
if (!$ ids ) {
@@ -439,17 +446,11 @@ protected function doFetch(array $ids)
439
446
return $ result ;
440
447
}
441
448
442
- /**
443
- * {@inheritdoc}
444
- */
445
449
protected function doHave (string $ id )
446
450
{
447
451
return (bool ) $ this ->redis ->exists ($ id );
448
452
}
449
453
450
- /**
451
- * {@inheritdoc}
452
- */
453
454
protected function doClear (string $ namespace )
454
455
{
455
456
if ($ this ->redis instanceof \Predis \ClientInterface) {
@@ -511,9 +512,6 @@ protected function doClear(string $namespace)
511
512
return $ cleared ;
512
513
}
513
514
514
- /**
515
- * {@inheritdoc}
516
- */
517
515
protected function doDelete (array $ ids )
518
516
{
519
517
if (!$ ids ) {
@@ -548,9 +546,6 @@ protected function doDelete(array $ids)
548
546
return true ;
549
547
}
550
548
551
- /**
552
- * {@inheritdoc}
553
- */
554
549
protected function doSave (array $ values , int $ lifetime )
555
550
{
556
551
if (!$ values = $ this ->marshaller ->marshall ($ values , $ failed )) {
0 commit comments