redis通信协议

redis通讯协议是基于RESP来实现的。由于redis过于优秀,所以很多公司内部的私有缓存也会去兼容RESP协议。

RESP本质是一种文本协议。也就是说,你直接抓包,是能看见明文的。

 

抓包命令:

 因为我客户端和服务器是同一台,所以走的是环回口。
tcpdump -i lo port 7000 -Ann
 
此外,抓包出来的玩意和实际用户看见的不一样。因为redis-cli.c的cliFormatReplyTTY函数对其进行了优化。方便用户查看。
 
 
Redis的命令使用的是redisCommand数据结构来管理的.
typedef void redisCommandProc(client *c);
typedef int *redisGetKeysProc(struct redisCommand *cmd, robj **argv, int argc, int *numkeys);
struct redisCommand {
char *name;
redisCommandProc *proc;
int arity;
char *sflags; /* Flags as string representation, one char per flag. */
int flags; /* The actual flags, obtained from the 'sflags' field. */
/* Use a function to determine keys arguments in a command line.
* Used for Redis Cluster redirect. */
redisGetKeysProc *getkeys_proc;
/* What keys should be loaded in background when calling this command? */
int firstkey; /* The first argument that's a key (0 = no keys) */
int lastkey; /* The last argument that's a key */
int keystep; /* The step between first and last key */
long long microseconds, calls;
};

 

针对sflag,有如下:

 

 
flag记录的是flag值与sflag进行位运算的结果,见populateCommandTable函数。
 
 
posted @ 2023-07-12 23:22  拿什么救赎  阅读(55)  评论(0编辑  收藏  举报