简体   繁体   English

我可以使用Redis容器[Docker]作为集群吗?

[英]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 ) 我正在使用docker-compose为我的Dev Env配置容器,我有3个容器(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 我正在使用Predis从php容器连接到Redis,我的问题是:当我做类似的事情时,我正在尝试在集群模式下工作

$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. 您可能需要获取redis容器的IP地址以进行连接。

(Assumin Linux) Run docker ps to find the name of the container (may be docker_redis_1), then docker inspect <container name> | grep IPAddress (在Linux中假定)运行docker docker ps来找到容器的名称(可能是docker_redis_1),然后docker docker inspect <container name> | grep IPAddress docker inspect <container name> | grep IPAddress . docker inspect <container name> | grep IPAddress Use this IP address in the connection - 在连接中使用此IP地址-

$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 如果您转到Predis Connection Factory,可以在Predis上找到可用的方案

and Predis support may protocols to communicate with an instance of Redis 和Predis支持可以与Redis实例进行通信的协议

tcp (TCP/IP), unix (UNIX domain sockets) or http (HTTP protocol through Webdis) tcp(TCP / IP),unix(UNIX域套接字)或http(通过Webdis的HTTP协议)

like it mention in Connection Parameters 喜欢它在连接参数中提到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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