Redis命令执行流程

整体流程

redis命令执行流程图

acceptTcpHandler -> anetTcpAccept -> acceptCommonHandler
acceptCommonHandler-> createClient -> readQueryFromClient

RedisServer处理Get命令流程

```


# RedisServer处理Set命令流程



# RedisClient发起请求流程


```c++
// file: src/hiredis.h 

/**
 * Redis连接上下文
 * Context for a connection to Redis
 */ 
typedef struct redisContext {
    const redisContextFuncs *funcs;   /* Function table */

    int err; /* Error flags, 0 when there is no error */
    char errstr[128]; /* String representation of error when applicable */
    redisFD fd;
    int flags;
    char *obuf; /* Write buffer */
    redisReader *reader; /* Protocol reader */

    enum redisConnectionType connection_type;
    struct timeval *timeout;

    struct {
        char *host;
        char *source_addr;
        int port;
    } tcp;

    struct {
        char *path;
    } unix_sock;

    /* For non-blocking connect */
    struct sockadr *saddr;
    size_t addrlen;

    /* Additional private data for hiredis addons such as SSL */
    void *privdata;
} redisContext;

Client-Server处理流程

// 

参考资料

[1] [Redis源码阅读]当你输入get/set命令的时候,Redis做了什么
[2] Redis(三):set/get 命令源码解析
[3] Redis 6.2当发送set String时,redis是如何处理的(源码)