I want to understand the network communication function implementation of Redis source code, such as Pub/Sub or stream communicate, or the underlying network implementation of Redis. Which part of the source code should I start with? If I want to make changes and improvements on the Redis source code, is this possible?
Comment From: uvletter
The network related functions mainly reside in ae.c and anet.c. ae.c models the eventloop, while anet.c encapsulates the operations to network. The use of network function is coupled with the business for a better performance, so it's maybe a little hard to recognize the outline how Redis react with network. Contribution is welcome.
Comment From: MasterL-min
Can I understand the network interaction process between the client and redis server in this way, if I enter redis-cli in the terminal, a TCP connection will be established with the server, and then I can send "set key good", which will send a message to the redis server ,this message is a encapsulated command, the redis server will parse the package and make corresponding processing.
Comment From: uvletter
Yes, it's also the basic way for any TCP server and client.
Message ID: @.***>
Comment From: MasterL-min
是的,这也是任何TCP服务器和客户端的基本方法。 消息 ID:@.***>
What is the difference between networking.c and ae.c and anet.c?
Comment From: uvletter
All network related biz logic reside in networking.c, such as client handling, input decoding, output encoding and so on. You can regard ae.c and anet.c as an individual and public library that can be also used by other programs, like redis-cli and so on, but networking.c contains the logic that's specific for redis-server.
Comment From: MasterL-min
If I want to use clion to debug the redis-server of redis, are there any more detailed tutorials?
Comment From: uvletter
Personally I don't recommend you start network programming study with Redis, the network part is tightly coupled with the business. Some universal network framework, like netty and libevent, is more clean and tiny for study. I know there're many blogs introducing the basic structures, and high level function like replication, cluster, persistence and so on, but the network part is a little trivial so not many attention on it, maybe you can turn to search engine for some help.
Comment From: MasterL-min
Thanks so much for your advice and help,wish you a happy life!
Comment From: MasterL-min
Personally I don't recommend you start network programming study with Redis, the network part is tightly coupled with the business. Some universal network framework, like netty and libevent, is more clean and tiny for study. I know there're many blogs introducing the basic structures, and high level function like replication, cluster, persistence and so on, but the network part is a little trivial so not many attention on it, maybe you can turn to search engine for some help.
Personally I don't recommend you start network programming study with Redis, the network part is tightly coupled with the business. Some universal network framework, like netty and libevent, is more clean and tiny for study. I know there're many blogs introducing the basic structures, and high level function like replication, cluster, persistence and so on, but the network part is a little trivial so not many attention on it, maybe you can turn to search engine for some help.
If I want to know how redis implements middleware communication, which part of redis code should I read, and should I mainly focus on his sub/pub command mechanism?
Comment From: uvletter
Recently I'm cumbered by other things, the reply may be late...
readQueryFromClient is the read event handler for clients, i.e. the entrance for requests processing, maybe which's you're looking for. sub/pub is a kind of somehow a little complex command, maybe you needn't dive into how the command implements, or you can begin with other simpler command, like PING, GET and so on.