此篇为对redis源码的个人理解和分析,以一个初看源码的视角从头阅读源码,对各个函数,定义的类型进行解释并阐明其作用,让初读源码的人能够完全理解该定义类型及函数,最后形成对redis总体的一个认知。希望此篇能为初读redis源码的人提供一些帮助。
acl.c文件
acl是 Access Control List的缩写,即访问控制列表,一个允许一些连接在可以执行的命令和可以访问的键方面受到限制的功能,具体redis官方文档中有:ACL | Redis
首先文件开头给出了各个类型的定义,acl文件开头提到如下定义:
rax *Users; /* Table mapping usernames to user structures. */
user *DefaultUser; /* Global reference to the default user.
Every new connection is associated to it, if no
AUTH or HELLO is used to authenticate with a
different user. */
list *UsersToLoad; /* This is a list of users found in the configuration file
that we'll need to load in the final stage of Redis
initialization, after all the modules are already
loaded. Every list element is a NULL terminated
array of SDS pointers: the first is the user name,
all the remaining pointers are ACL rules in the same
format as ACLSetUser(). */
list *ACLLog; /* Our security log, the user is able to inspect that
using the ACL LOG command .*/
static rax *commandId = NULL; /* Command name to id mapping */
static unsigned long nextid = 0; /* Next command id that has not been assigned */
定义了Users;DefaultUser,UsersToload,acllog,即给出用户名等信息,同时定义了安全日志。
rax,list均为redis中定义的基本类型,后多个文件中会用到,故先解释rax和list。
rax定义
有关rax定义可在rax.c和rax.h文件中找到,简单来讲rax为redis自实现的基数树,从构造上讲,也叫前缀树/前缀压缩树,可以存储字符串和值,类似于字典树的升级版,具体代码后面在讲rax.c和rax.h文件会进行分析。

本文主要分析Redis源码中的acl.c文件,介绍了访问控制列表(ACL)的概念,详细讲解了rax(基数树)和list(双向链表)的基础定义。此外,还涵盖了ACLUserFlags和ACLSelectorFlags的定义,以及ACLCheckPasswordHash等关键函数的作用,旨在帮助初学者理解Redis的源码实现。

1160

被折叠的 条评论
为什么被折叠?



