0

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

Klamius
  • 167
  • 2
  • 10

2 Answers2

0

You will probably need to get the IP address of the redis container for the connection.

(Assumin Linux) Run docker ps to find the name of the container (may be docker_redis_1), then docker inspect <container name> | grep IPAddress. Use this IP address in the connection -

$options    = ['cluster' => '<IP Address of container>'];
Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • Would be more useful if you gave some more information than 'it's not working'. Are you getting any errors? – Nigel Ren Oct 17 '17 at 14:20
  • well, I tried to do somthing like that $parameters = ['tcp://172.19.0.4:6379'] but client was not able to establish the connection – Klamius Oct 17 '17 at 14:22
0

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

Klamius
  • 167
  • 2
  • 10