Redis server/client/sentinel/cluster, redissentinel

Source: Internet
Author: User
Tags redis cluster

Redis server/client/sentinel/cluster, redissentinel

Server/client/sentinel/cluster in redis

The redis Server is a one-to-many architecture. The server uses the I/O multiplexing technology to process file events and processes requests from multiple clients in a single thread and single process. struct redisServer {// stores the list * clients;/* List of active clients * // linked list, and stores the list * clients_to_close of all clients to be closed; /* Clients to close asynchronously */} indicates the redisServer structure of the server in redis. It can be seen that all the clients on the server are saved in the list of Clients. the client can be divided into two types: fake clint, which does not require socket connection. It is mainly used to load the execution process of AOF and Lua scripts. In the redisClient structure, if it is fake clent Fd =-1, and fd is not equal to-1, indicating that the normal client can list the current CLIENT through the client list. If typedef struct redisClient {// fake client, fd is equal to-1 int fd; // the name of the client. You can use the clint list to query robj * name; /* As set by client setname * // Save the command request sds querybuf sent by the CLIENT; // query the buffer length peak value size_t querybuf_peak;/* Recent (100 ms or more) peak of querybuf size * // number of parameters int argc; // parameter object array robj ** argv; // record the command struct redisCommand * cmd, * lastcmd executed by the client; // Indicates the status of the client, revealing the int flags of the current clint;/* REDIS_SLAVE | REDIS_MONITOR | REDIS_MULTI... * /// indicates whether the client is authenticated. 0 indicates that the client is not authenticated. If the client is not authenticated, the AUTH command can only be executed. int authenticated;/* when requirepass is non-NULL * // * Response buffer * // returns the int bufpos offset; // The command response obtained by executing the command will be saved to this buffer zone. Each clint has two buffers and one fixed buffer zone is 16 k. // The fixed buffer is represented by the buf array, and the other is the dynamic buffer list * reply to represent the char buf [REDIS_REPLY_CHUNK_BYTES];} redisClient; 1. redis users can use the slaveeof command or set the slaveof option to let one server copy another server. 2. the value assignment function of redis is divided into two operations: sync and command propagate. When the slave server sends sync to the master server, the master server generates an rbd file through bgsave reputation and sends it to the slave server. The slave server loads This rbd file, at the same time, the master server sends all write commands recorded in the buffer zone to the slave server. After the slave server loads rbd and executes the write command sent by the master server, the status is the same as that of the master server. In the future, the master server will continuously send commands in the buffer period to the slave server. in redis 2.8, The psync command can be used to complete the re-synchronization and partial re-synchronization. partial re-synchronization is composed of the following three parts: 1): The replication offset of the master-slave server 2 ): the master server's replication backlog buffer, which is a fixed out-of-band FIFO with a default size of 1 m3): the ID of the server running, consisting of 40 random hexadecimal characters: sentinel is a highly reliable redis solution. 5: sentinel is a dedicated code used to replace some common redis servers with sentinel. Therefore, sentinel is essentially supported by servers such as common servers. In redis. struct redisCommand redisCommandTable [] = {"get", getCommand, 2, "r", 0, NULL, 0} In redisCommandTable }, {"set", setCommand,-3, "wm", 0, NULL, 0}, {"setnx", setnxCommand, 3, "wm", 0, NULL, 0 },{ "setex", setexCommand, 4, "wm", 0, NULL, 0 },{ "psetex", psetexCommand, 4, "wm", 0, NULL, 0}, {"append", appendCommand, 3, "wm", 0, NULL, 0 },{ "strlen", strlenCommand, 2, "r", 0, NULL,, 0}, {"del", delCommand,-2, "w", 0, NULL, 1,-,}, {"exists", existsCommand, 2, "r", 0, NULL, 0}, {"setbit", setbitCommand, 4, "wm", 0, NULL, 0 },{ "getbit", getbitCommand, 3, "r", 0, NULL, 0 },...} However, the commands supported by sentinel are in sentinel. the following commands are supported in c: struct redisCommand sentinelcmds [] = {"ping", pingCommand, 1, "", 0, NULL, 0, 0 }, {"sentinel", sentinelCommand,-2, "", 0, NULL, 0, 0, 0}, {"subscribe", subscribeCommand,-2, "", 0, NULL, 0}, {"unsubscribe", unsubscribeCommand,-1, "", 0, NULL, 0}, {"psubscribe", psubscribeCommand, -2, "", 0, NULL, 0, 0, 0, 0}, {"punsubscribe", punsubscribeCommand,-1, "", 0, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },{ "publish", sentinelPublishCommand, 3, "", 0, NULL, 0, 0, 0, 0 },{ "info", sentinelInfoCommand,-1 ,"", 0, NULL, 0}, {"shutdown", shutdownCommand,-1, "", 0, NULL, 0, 0 }}; it can be seen that the commands supported by sentinel are much less than common servers. 6: sentinelState mainly stores the State related to the sentinel function. 7: Each sentinelRedisInstance represents a redis server instance monitored by sentinel. 8: each master server monitored by sentinel creates command connections and subscription connections. 9: by default, sentinel will send the info command to the master server that monitors the north at a frequency of 10 seconds. By analyzing the response of the info command, sentinel will obtain the current information of the master server 10: sentinel sends ping commands to other instances, including the master server, slave server, and other sentinel instances, and determines whether the instances are online based on the reply to the ping command. 11: redis cluster may be built through cluster meet ip + port 12: nodes in the redis cluster will continue to use all servers used in standalone mode. node data will be in the clusterNode structure. 13: The slot is used between nodes to identify the node on which the current data is saved. You can use cluster info to view the node information, add slot through cluster addslots. there are a total of 16383 slot.14: new nodes can be added, which will lead to slot reallocation, which is called sharding.

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.