PHP Redis Client and Cluster

本文介绍如何使用 PHP 连接并配置 Redis 集群。通过示例代码展示了如何设置 Redis 客户端集群,并列举了具体的连接配置参数。同时提供了遇到连接错误时的异常处理方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

PHP Redis Client and Cluster

Set up the Redis Cluster
try {
$this->clientCluster = new Client($redisHostCluster, array('cluster' => 'redis'));
$logger->debug("Successfully set up Redis");
} catch (\Exception $e) {
$logger->error("Couldn't connected to Redis");
$logger->error($e->getMessage());
}

The settings are here in the .ini
redisHostCluster[] = 'tcp://cluster-jobs-0001-001.pnuura.0001.use1.cache.amazonaws.com?timeout=10&read_write_timeout=10'
redisHostCluster[] = 'tcp://cluster-jobs-0001-002.pnuura.0001.use1.cache.amazonaws.com?timeout=10&read_write_timeout=10'
redisHostCluster[] = 'tcp://cluster-jobs-0002-001.pnuura.0001.use1.cache.amazonaws.com?timeout=10&read_write_timeout=10'
redisHostCluster[] = 'tcp://cluster-jobs-0002-002.pnuura.0001.use1.cache.amazonaws.com?timeout=10&read_write_timeout=10'
redisHostCluster[] = 'tcp://cluster-jobs-0003-001.pnuura.0001.use1.cache.amazonaws.com?timeout=10&read_write_timeout=10'
redisHostCluster[] = 'tcp://cluster-jobs-0003-002.pnuura.0001.use1.cache.amazonaws.com?timeout=10&read_write_timeout=10'

In the ConfigUtil, it will automatically load the array.
$redisHostCluster = $config['redisHostCluster'];

References:
http://stackoverflow.com/questions/35599977/redisclusterexception-with-phpredis-when-connecting-to-redis-cluster-which-is-no
https://www.zybuluo.com/phper/note/248555
https://github.com/nrk/predis
https://github.com/nrk/predis/wiki
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值