8000 `RedisTrait` loses database with multiple persistent connections · Issue #51578 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
RedisTrait loses database with multiple persistent connections #51578
Closed
@uncaught

Description

@uncaught

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:

|| ($params['dbindex'] && !$redis->select($params['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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0