当前位置:网站首页>Random talk on redis source code 119
Random talk on redis source code 119
2022-06-22 20:05:00 【Tao song remains the same】
This note is very clear :
/* Create a new user with the specified name, store it in the list
* of users (the Users global radix tree), and returns a reference to
* the structure representing the user.
*
* If the user with such name already exists NULL is returned. */
user *ACLCreateUser(const char *name, size_t namelen) {
if (raxFind(Users,(unsigned char*)name,namelen) != raxNotFound) return NULL;
user *u = zmalloc(sizeof(*u));
u->name = sdsnewlen(name,namelen);
u->flags = USER_FLAG_DISABLED | server.acl_pubsub_default;
u->allowed_subcommands = NULL;
u->passwords = listCreate();
u->patterns = listCreate();
u->channels = listCreate();
listSetMatchMethod(u->passwords,ACLListMatchSds);
listSetFreeMethod(u->passwords,ACLListFreeSds);
listSetDupMethod(u->passwords,ACLListDupSds);
listSetMatchMethod(u->patterns,ACLListMatchSds);
listSetFreeMethod(u->patterns,ACLListFreeSds);
listSetDupMethod(u->patterns,ACLListDupSds);
listSetMatchMethod(u->channels,ACLListMatchSds);
listSetFreeMethod(u->channels,ACLListFreeSds);
listSetDupMethod(u->channels,ACLListDupSds);
memset(u->allowed_commands,0,sizeof(u->allowed_commands));
raxInsert(Users,(unsigned char*)name,namelen,u,NULL);
return u;
}
/* This function should be called when we need an unlinked "fake" user
* we can use in order to validate ACL rules or for other similar reasons.
* The user will not get linked to the Users radix tree. The returned
* user should be released with ACLFreeUser() as usually. */
user *ACLCreateUnlinkedUser(void) {
char username[64];
for (int j = 0; ; j++) {
snprintf(username,sizeof(username),"__fakeuser:%d__",j);
user *fakeuser = ACLCreateUser(username,strlen(username));
if (fakeuser == NULL) continue;
int retval = raxRemove(Users,(unsigned char*) username,
strlen(username),NULL);
serverAssert(retval != 0);
return fakeuser;
}
}
边栏推荐
猜你喜欢

数字经济加速落地,能为中小企业带来什么?

Nlp-d57-nlp competition D26 & skimming questions D13 & reading papers & finding bugs for more than an hour

matplotlib设置坐标轴刻度间隔

0.0 - how can SolidWorks be uninstalled cleanly?

Matplotlib set axis scale interval

51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭

【深入理解TcaplusDB技术】查看TcaplusDB线上运行情况

critical path
![[in depth understanding of tcaplus DB technology] Introduction to tcaplus JDBC development](/img/2b/3ab5e247ac103728b4d3579c3c5468.png)
[in depth understanding of tcaplus DB technology] Introduction to tcaplus JDBC development

图的定义及术语
随机推荐
MySQL数据库基本操作
图的定义及术语
漫话Redis源码之一百二十二
Metu stability and operation and maintenance guarantee scheme
B tree code (C language)
【深入理解TcaplusDB技术】入门Tcaplus SQL Driver
MySQL数据库DQL查询操作
芯和半导体“射频EDA/滤波器设计平台”闪耀IMS2022
【深入理解TcaplusDB技术】查看TcaplusDB线上运行情况
【深入理解TcaplusDB技术】TcaplusDB机型
第一篇 热身--隐式类型转换还是其他?
lua--迭代器、模块、元表
Huffman tree (C language)
[deeply understand tcapulusdb technology] tcapulusdb table management - modify table
树和森林的遍历
Mysql database knowledge points (III)
matlab调用API
critical path
商业智能BI数据仓库中的指标、维度和模型到底是什么?
Geometrical product specifications (GPS) - ISO code system for linear dimensional tolerances