Error while iterating on `Predis\Client`: `Object of class Predis\Connection\Aggregate\MasterSlaveReplication could not be converted to string`
Author: Gregoire-MCreated Jan 6, 2023Updated Mar 11, 2025
Labelsbug
Describe the bug
I get a fatal error when iterating on a Predis\Client instance which connection is a Predis\Connection\Aggregate\MasterSlaveReplication instance.
To Reproduce
With snc/redis-bundle 4.4.2 and predis/predis 1.1.10, Symfony 5.4.16, and php 8.1.11 and the following config:
snc_redis:
clients:
default:
type: predis
alias: default
dsn:
- "%env(REDIS_URL)%?alias=master"
- "%env(REDIS_URL_READ_ONLY)%"
logging: '%kernel.debug%'
options:
replication: trueThen run:
$ bin/console redis:query flushall -vvv
In Client.php line 540:
[Error]
Object of class Predis\Connection\Aggregate\MasterSlaveReplication could not be converted to string
Exception trace:
at /srv/app/vendor/predis/predis/src/Client.php:540
Predis\Client->getIterator() at /srv/app/vendor/snc/redis-bundle/src/Command/RedisQueryCommand.php:86
Snc\RedisBundle\Command\RedisQueryCommand->execute() at /srv/app/vendor/symfony/console/Command/Command.php:312
Symfony\Component\Console\Command\Command->run() at /srv/app/vendor/symfony/console/Application.php:1038
Symfony\Component\Console\Application->doRunCommand() at /srv/app/vendor/symfony/framework-bundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /srv/app/vendor/symfony/console/Application.php:312
Symfony\Component\Console\Application->doRun() at /srv/app/vendor/symfony/framework-bundle/Console/Application.php:82
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /srv/app/vendor/symfony/console/Application.php:168
Symfony\Component\Console\Application->run() at /srv/app/bin/console:43
redis:query [--client CLIENT] [--] <query>...Expected behavior It should output:
DEBUG [snc_redis] Executing command "FLUSHALL"
^ Predis\Response\Status^ {#389
-payload: "OK"
}Versions (please complete the following information):
- Predis: 1.1.10
- snc/redis-bundle 4.4.2
- Symfony 5.4.16
- PHP 8.1.11
- Redis Server: bitnami/redis:6.2.6
Code sample The code that tries to iterate on the client is here.
Additional context N/A
Source: predis/predis