Home > Backend Development > PHP Problem > Does phpredis support clustering?

Does phpredis support clustering?

(*-*)浩
Release: 2023-02-26 10:28:01
Original
4290 people have browsed it

php To operate the redis cluster cluster, you need to use the phpredis extension. This is a c extension with higher performance.

Does phpredis support clustering?

phpredis cluster usage (recommended learning: PHP video tutorial)

<?php
$redis_list = [&#39;10.30.5.162:7000&#39;,&#39;10.30.5.163:7000&#39;,&#39;10.30.5.163:7001&#39;];
$client = new RedisCluster(NUll,$redis_list);
echo $client->get(&#39;new_item_key:d89b561fb759fd533a8c2781ef15dd5f&#39;)
Copy after login

Code description

The first parameter is NULL. Don’t ask me, I don’t know why. Anyway, I couldn’t find the document, and I didn’t understand this article.

The second parameter is the list of master servers of the redis cluster we need to connect to. We have 3 masters, so just fill in 3, you can fill in one master node, or even fill in one slave node, but the performance will be different.

Cluster Principle

Why can redisCluster be operated by filling in any node address?

In cluster mode, Redis receives any key-related commands First calculate the slot corresponding to the key.

If the slave node is initialized, the redis command will first be sent to the slave node.

The slave node finds the corresponding node according to the slot. If the node is If it is itself, it will process the key command;

If it is not itself, it will cause a MOVED redirection error and notify the client to request the correct node. This process is called MOVED redirection

Does phpredis support clustering?

The redirection information contains the slot corresponding to the key and the node address responsible for the slot. Based on this information, the client can redirect to the correct When a node initiates a request, the phpredis client can directly initiate a request to the node where the key is located based on the redirection information to obtain the data

The above is the detailed content of Does phpredis support clustering?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template