PHP operation redis cluster sentinel mode

Some time ago, the redis cluster sentinel deployment was just used in the project. Because I didn't know it before, I was dumbfounded and consulted a few pieces of information. I hereby summarize it as a record.

Write on the frontier: As the project expands, the dependence on redis is also increasing. In order to enhance the performance of redis and prevent it from hanging down, the first attempt to use the redis sentinel in the project to monitor the redis cluster.

 

Sentinel mode: I have looked at the principle roughly and did not understand it in detail. If something is wrong, ask for advice. Monitor the heartbeat package of the redis master library. If the heartbeat is disconnected, enumerate a slave library to become the new master library to prevent redis from being down

This method is completed by the rawCommand function in the php-redis extension (this function must be installed with the php-redis extension of 2.2.7 or above). If you do not understand the working principle of the sentry mode, you can query it first. To help understand, I just checked it briefly,


// Initialize redis object
$ redis = new Redis ();
// Connect the sentinel service host as ip, port as port, sentry ip and port number
$ redis-> connect ($ host, $ port);

// Get the main library list and its status information
$ result = $ redis-> rawCommand ('SENTINEL', 'masters');

// Get the information corresponding to the name in accordance with the master repository configured redis
// should master_name (the information may be acquired in the previous step) by the operation and maintenance informing
$ result = $ redis-> rawCommand ( 'SENTINEL', 'master', $ master_name);

// According to the configured master library redis name to obtain its corresponding slave library list and its information
$ result = redis-> rawCommand ('SENTINEL', 'slaves', $ master_name);

// Get the redis main library address of a specific name
$ result = $ redis-> rawCommand ('SENTINEL', 'get-master-addr-by-name', $ master_name)
// The above part can get the IP and Corresponding to the port, the program can be directly used as a link to a single redis link operation 
————————————————
Copyright Notice: This article is the original article of the CSDN blogger "Dajin Chain Small Watch" Follow the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement.
Original link: https://blog.csdn.net/u010824676/article/details/81011887

Guess you like

Origin www.cnblogs.com/myJuly/p/12686520.html