PHP Operation Redis Cluster cluster

Source: Internet
Author: User
Tags install php redis cluster

There are two ways PHP will operate the Redis cluster cluster:

1, use Phpredis extension, this is a C extension, performance is higher, but phpredis2.x extension does not, need to upgrade Phpredis to 3.0, but this program reference very few

2, using Predis, pure PHP development, using the namespace, need to php5.3+, high flexibility

I'm using Predis, and I'm loading the address https://github.com/nrk/predis/zipball/master.
After downloading the package is:
Nrk-predis-v1.1.0-65-gd72f067.zip
Upload to the server, after decompression:
Unzip Nrk-predis-v1.1.0-65-gd72f067.zip
After downloading, rename to Predis,

mv nrk-predis-d72f067 predismv predis /data/www/facx195.com

Note that my environment is PHP, so there is no need to install PHP Phpredis extension in the LNMP environment also can request PHP files in the browser to obtain data in Redis

The instance environment for Redis is:

192.168.2.106:20380192.168.2.106:31680192.168.2.107:20380192.168.2.107:31680192.168.2.99:20380192.168.2.99:31680

[Email protected] wwwlogs]# cat/data/www/facx195.com/predis.php

<?phprequire ‘/data/www/fx195.com/predis/autoload.php‘;//引入predis相关包//redis实例$servers = array(    ‘tcp://192.168.2.99:20380‘,    ‘tcp://192.168.2.106:31680‘,    ‘tcp://192.168.2.107:20380‘,    ‘tcp://192.168.2.99:31680‘,    ‘tcp://192.168.2.106:20380‘,    ‘tcp://192.168.2.107:31680‘,);$client = new Predis\Client($servers, array(‘cluster‘ => ‘redis‘));$client->set("name4", "44");$client->set("name5", "55");$client->set("name6", "66");$name1 = $client->get(‘name4‘);$name2 = $client->get(‘name5‘);$name3 = $client->get(‘name6‘);var_dump($name1, $name2, $name3);die;?>

The Name1,name2,name3 is a 3 key, which is allocated to 3 slots according to the algorithm, and may be divided into 3 servers

Run predis.php first to see the results:


Then log on to the Redis client for cluster validation:

[Email protected] ~]# redis-cli-h 192.168.2.106-p 20380-c

Log on to Redis on the 99 machine, error, because the 99 machine on the Redis has been turned off, but this does not restart the 99 machine after the Redis instance login 99 on the machine, Redis cannot find the data

Start 2 Redis on the 192.168.2.99

Resources:
52136918

PHP Operation Redis Cluster cluster

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.