php 连接集群

最后更新于:2022-04-02 04:00:49

[TOC] ## predis (php 扩展) 连接集群 ### 安装 `composer require predis/predis` ### 使用 节点只使用一个也可以 ``` use Predis\Client; require __DIR__ . '/../vendor/autoload.php'; // 写一个节点也可以 $redis_list = [ 'tcp://10.30.5.163:7000', 'tcp://10.30.5.163:7001', 'tcp://10.30.5.162:7000' ]; $redis = new Client($redis_list, ['cluster'=>'redis']); echo $redis->get('new_item_key:d89b561fb759fd533a8c2781ef15dd5f'); ``` ## phpredis (C 扩展) ### 安装 ``` git clone -b feature/redis_cluster git@github.com:phpredis/phpredis.git cd phpredis phpize ./configure make make install //extension=redis.so ``` ### 使用 ``` $redis_list = ['10.30.5.162:7000','10.30.5.163:7000','10.30.5.163:7001']; $client = new RedisCluster(NUll,$redis_list); echo $client->get('new_item_key:d89b561fb759fd533a8c2781ef15dd5f'); ```
';