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函数。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
2022-07-12 redis中客户端结构体