1、下载群集扩展

wgethttps://github.com/nrk/predis/archive/v1.0.zipunzipv1.0cp-Rfpredis-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=newPredis\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能调用的目录就行