Redis code structure 2 net, main, event

Source: Internet
Author: User

Redis code structure 2 net, main, event

1. Network Library
Anet. C and networking. C: These two files mainly implement network communication and interaction with the client.
1.1 Anet. c
This file encapsulates basic network socket operations (TCP, unixsock). Here we will briefly describe the functions through the caller. (Some functions are not used yet)
Functions used by server:
Int anettcpserver (char * err, int port, char * bindaddr). This function is called during initserver. It calls anetcreatesocket to create a socket FD (so_reuseaddr is supported, and then anetlisten listens to the port specified by the server.
The second server function is int anettcpaccept (char * err, int S, char * IP, int * port). This function is called by the accepttcphandler function, that is, the current listening socket, after receiving a client connect, call the accepttcphandler function to receive it, create the client socket for communication, and create a redisclient object createclient (FD ), the function calls the other two functions of the file anetnonblock (null, FD); anettcpnodelay (null, FD); set the socket to non-blocking, and disable the Nagle algorithm (that is, merge tabloids into large packets and forward them, but directly send tabloids ).
In addition, int anetpeertostring (int fd, char * IP, int * port) is used to locate the IP address and port corresponding to socket FD.
Functions used by the client:
Int anettcpconnect (char * err, char * ADDR, int port) creates a socket FD and connects it to the specified server. And the socket is blocked.
Int anettcpnonblockconnect (char * err, char * ADDR, int port), which is used by the replication slave and creates a non-blocking Socket FD. |
Summary: Listen uses blocking Io, while server connect uses non-blocking Io. Generally, client connect uses blocking Io, and slave connect uses non-blocking Io. Several of these functions are about unixsocket, which is the same as tcpsocket. They are not used in the current version.
1.2 Networking. C: see

Http://blog.csdn.net/wudongxu/article/details/7005830

2. Main
We classify redis's main framework file, config-related files, and dictionary-related files into this module. Redis main function and servercron process, we have introduced in the previous article, and DB. C and dict. c mainly involves the relationship of several important data structures, see http://hi.csdn.net/attachment/201111/28/0_13224455853iSZ.gif

3. Event Library
This library includes AE. C, AE _epoll.c, AE _kqueue.c, AE _select.c, and syncio. C. Among them, AE. C is responsible for the entire service process AE _epoll.c, AE _kqueue.c, and AE _select.c are three different Io reuse methods. Epoll is used by default. syncio. C is used to block Io synchronization operations. This file is mainly used between master-slave and migrate commands.
Redis uses non-blocking Io when processing user requests, and uses the

The main content of these three databases has been described in the previous articles. There are no more descriptions here.

Related Article

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.