Search code examples
phpdockerredisdocker-composepredis

Can I use Redis container [Docker] as cluster?


I am using docker-compose to configure containers for my Dev Env and I have 3 containers ( nginx, php, redis )

version: '3'

services:
    php:
        ..
    nginx:
        ..
    redis:
        image: redis
        ports:
          - 6379:6379

I am using Predis to connect to redis from php container , my question is : I am trying to work in clustering mode, when I do something like that

$parameters = ['redis'];
$options    = ['cluster' => 'redis'];

$client = new Predis\Client($parameters, $options);

is not working


Solution

  • I was able to solve this issue by changing the host url like that

    $parameters = ['redis://redis'];
    

    you can find may schemes available on Predis if you go to Predis Connection Factory

    and Predis support may protocols to communicate with an instance of Redis

    tcp (TCP/IP), unix (UNIX domain sockets) or http (HTTP protocol through Webdis)

    like it mention in Connection Parameters