Closed
Description
Symfony version(s) affected
6.*
Description
Due to a bug in phpredis, the persistent redis connections are not keeping their desired selected database.
Specifically connections that are supposed to be on dbindex 0
end up on other databases. This is because the RedisTrait only calls select
for a truthy dbindex:
I'm wondering if you would consider calling select
every time, not just for a truthy dbindex in case the connection is persistent?
I know this would be a workaround for a Symfony-external bug, but it's a small fix.
How to reproduce
Have two persistent cache connections on different DBs, e.g.:
services:
_defaults:
autowire: true
autoconfigure: true
redis_db_0:
class: Redis
factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', createConnection]
arguments:
- '%env(REDIS_DSN)%'
- dbindex: 0
lazy: true
persistent: 1
persistent_id: 'db0'
redis_db_1:
class: Redis
factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', createConnection]
arguments:
- '%env(REDIS_DSN)%'
- dbindex: 1
lazy: true
persistent: 1
persistent_id: 'db1'
Possible Solution
Change the dbindex check:
- || ($params['dbindex'] && !$redis->select($params['dbindex']))
+ || (($params['dbindex'] || $connect === 'pconnect') && !$redis->select($params['dbindex']))
Additional Context
No response