Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes phpredis persistent connections when clients connect to different DBs #276

Closed

Conversation

andreausu
Copy link

This fixes the corner case where clients connecting to different redis databases are used with persistent connection enabled by giving a unique ID to the persistent connections.

eg:

config:

snc_redis:
    clients:
        db1:
            type: phpredis
            alias: db1
            dsn: redis://localhost/1
            logging: %kernel.debug%
            options:
                connection_persistent: true

        db2:
            type: phpredis
            alias: db2
            dsn: redis://localhost/2
            logging: %kernel.debug%
            options:
                connection_persistent: true

code:

$db1 = $this->getContainer()->get('snc_redis.db1');
$db2 = $this->getContainer()->get('snc_redis.db2');
$db1->set('cachekey1', 'cachevalue');
$db2->set('importantkey2', 'importantvalue');
$db1->flushDb(); // db 2 will be flushed instead of db 1 

From phpredis documentation:

$redis->pconnect('127.0.0.1', 6379, 2.5, 'x'); // x is sent as persistent_id and would be another connection the the three before.

@snc
Copy link
Owner

snc commented Dec 11, 2016

Closing this in favor of #308.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants