简体   繁体   中英

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

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 docker inspect <container name> | grep IPAddress . Use this IP address in the connection -

$options    = ['cluster' => '<IP Address of container>'];

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM