redis docker 搭建集群以及使用 php predis操作集群

// 配置文件下载地址
wget http://download.redis.io/redis-stable/redis.conf
wget http://download.redis.io/redis-stable/sentinel.conf
// 配置文件
cluster-enabled yes
cluster-node-timeout 10000
cluster-config-file nodes.conf
// 6个配置文件端口 7001 - 7006
// 启动6个redis容器 使用 --net host 网络
docker run --name r1  --net=host -v /root/config/redis/cluster/r1.conf:/etc/redis/redis.conf -v /root/config/redis/cluster/node.conf:/etc/redis/node.conf -d redis redis-server /etc/redis/redis.conf --appendonly yes 

docker run --name r2  --net=host -v /root/config/redis/cluster/r2.conf:/etc/redis/redis.conf -v /root/config/redis/cluster/node.conf:/etc/redis/node.conf -d redis redis-server /etc/redis/redis.conf --appendonly yes 

docker run --name r3  --net=host -v /root/config/redis/cluster/r3.conf:/etc/redis/redis.conf -v /root/config/redis/cluster/node.conf:/etc/redis/node.conf -d redis redis-server /etc/redis/redis.conf --appendonly yes 


docker run --name s1  --net=host -v /root/config/redis/cluster/s1.conf:/etc/redis/redis.conf -v /root/config/redis/cluster/node.conf:/etc/redis/node.conf -d redis redis-server /etc/redis/redis.conf --appendonly yes 

docker run --name s2  --net=host -v /root/config/redis/cluster/s2.conf:/etc/redis/redis.conf -v /root/config/redis/cluster/node.conf:/etc/redis/node.conf -d redis redis-server /etc/redis/redis.conf --appendonly yes 

docker run --name s3  --net=host -v /root/config/redis/cluster/s3.conf:/etc/redis/redis.conf -v /root/config/redis/cluster/node.conf:/etc/redis/node.conf -d redis redis-server /etc/redis/redis.conf --appendonly yes
// 搭建集群
// 进入某个容器或者宿主机安装了redis
redis-cli --cluster create --cluster-replicas 1 ip:7001 ip:7002 ip:7003 ip:7004 ip:7005 ip:7006
// php操作集群
<?php
require  "vendor/autoload.php";
$servers = [
     'tcp://ip:7001',
     'tcp://ip:7002',
     'tcp://ip:7003',
     'tcp://ip:7004',
     'tcp://ip:7005',
     'tcp://ip:7006',
 ];

$client = new Predis\Client($servers, array('cluster' => 'redis'));
  
$r = $client->lpush("list", array(1, 2, 3, 4, 5));
$list = $client->lrange("list", 0, -1);
var_dump($r, $list);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值