先搭建好redis集群,我的搭建好了,给你们看下
我的是3主3从。
接下来我们用predis来测试集群。predis是php生态里面的一个composer包
<?php
require __DIR__.'/vendor/predis/predis/autoload.php';//引入predis相关包
//redis实例
$servers = array(
'tcp://192.168.139.138:7000',
'tcp://192.168.139.138:7001',
'tcp://192.168.139.138:7002',
'tcp://192.168.139.138:7003',
'tcp://192.168.139.138:7004',
'tcp://192.168.139.138:7005',
);
$options = ['cluster' =>'redis','parameters' => [
'password' => '123456'
]];
$client = new Predis\Client($servers, $options);
$client->set('w4',100);
测试完成。