1. 程式人生 > >PHP 通過redis-sentine操作redis

PHP 通過redis-sentine操作redis

這裡介紹過客戶端連線php-redis一般必須要在主節點來做寫操做。從節點讀操做~ 這裡需要客戶端自己完成一部分操作 https://mp.csdn.net/mdeditor/82852429#

自動載入~
// Prepend a base path if Predis is not available in your "include_path".
require 'Predis/Autoloader.php';


$sentinels = ['tcp://127.0.0.1:26379', 'tcp://127.0.0.1:26380', 'tcp://127.0.0.1:26381'];
$options   = ['replication' => 'sentinel', 'service' => 'mymaster'];
$client = new Predis\Client($sentinels, $options);

for($i=0;$i<100000;$i++){
    $client->set($i, "test".$i);
    $result = $client->get($i);
    echo date('y-m-d h:i:s',time());
    echo " ".$result."\n";
}