1、下载群集扩展
| 1234 | wget https://github.com/nrk/predis/archive/v1.0.zipunzip v1.0cp -Rf predis-1.0 /u01/html/predis注:/u01/html为系统目录 |
2、连接redis集群
<?php//连接本地的 Redis 服务require 'predis/autoload.php';$parameters = ['tcp://192.168.1.231:7003', 'tcp://192.168.1.231:7003', 'tcp://192.168.1.231:7005'];$options = ['cluster' => 'redis'];$redis = new Predis\Client($parameters, $options);$x=rand(10,100);//设置 redis 字符串数据$redis->set("y".$x, "tank".$x*2); // 获取存储的数据并输出$result = $redis->get("y".$x); //输出结果echo $result;?> |
注:Predis只是几个PHP文件,不需要安装到PHP扩展中,只需要把文件拷到php能调用的目录就行
热门评论
-
栋公子2020-01-05 0
查看全部评论你这里的tcp://127.0.0.1:7003,这些是主节点的还是从节点的,还是主从都要写呀