code format

This commit is contained in:
LingZhaoHui 2023-05-13 02:36:33 +08:00
parent 8df4a09922
commit 51a76f3e12
Signed by: zeekling
GPG Key ID: D96E4E75267CA2CC
2 changed files with 33 additions and 36 deletions

View File

@ -7,18 +7,18 @@ static RedisModuleCommandFilter *filter;
void AuthFilter_CommandFilter(RedisModuleCommandFilter *filter) {
int log = 0;
int pos = 0;
RedisModule_Log(NULL, LOG_LEVL_NOTICE, "command filter");
RedisModule_Log(NULL, LOG_LEVEL_NOTICE, "command filter");
while (pos < RedisModule_CommandFilterArgsCount(filter)) {
const RedisModuleString *arg = RedisModule_CommandFilterArgGet(filter, pos);
size_t arg_len;
const char *arg_str = RedisModule_StringPtrLen(arg, &arg_len);
RedisModule_Log(NULL, LOG_LEVL_NOTICE, "str=%s,len=%d", arg_str, arg_len);
RedisModule_Log(NULL, LOG_LEVEL_NOTICE, "str=%s,len=%d", arg_str, arg_len);
// 解密
pos++;
}
RedisModuleUser *user = RedisModule_CreateModuleUser("default");
if (user == NULL) {
RedisModule_Log(NULL, LOG_LEVL_NOTICE, "user is null");
RedisModule_Log(NULL, LOG_LEVEL_NOTICE, "user is null");
}
@ -29,31 +29,27 @@ int AuthCommand_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
return REDISMODULE_OK;
}
void create_users(RedisModuleCtx *ctx) {
RedisModuleUser *user = RedisModule_CreateModuleUser("default");
RedisModule_SetModuleUserACL(user, "allcommands");
RedisModule_SetModuleUserACL(user, "allkeys");
RedisModule_SetModuleUserACL(user, "on");
RedisModule_Log(ctx, LOG_LEVL_NOTICE, "init module user success!");
RedisModule_FreeModuleUser(user);
}
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
REDISMODULE_NOT_USED(argv);
REDISMODULE_NOT_USED(argc);
if (RedisModule_Init(ctx, "redis-auth", 1, REDISMODULE_APIVER_1) == REDISMODULE_ERR) {
RedisModule_Log(ctx, LOG_LEVL_NOTICE, "init redis-auth failed");
RedisModule_Log(ctx, LOG_LEVEL_NOTICE, "init redis-auth failed");
return REDISMODULE_ERR;
}
create_users(ctx);
filter = RedisModule_RegisterCommandFilter(ctx, AuthFilter_CommandFilter, 0);
if (filter == NULL) {
RedisModule_Log(ctx, LOG_LEVEL_WARNING, "init filter failed");
return REDISMODULE_ERR;
}
RedisModule_Log(ctx, LOG_LEVL_NOTICE, "init redis-auth success!");
if (RedisModule_CreateCommand(ctx, "acl.auth", AuthCommand_RedisCommand,
"no-auth", 0,0,0) == REDISMODULE_ERR) {
RedisModule_Log(ctx, LOG_LEVEL_WARNING, "init acl.auth failed");
return REDISMODULE_ERR;
}
RedisModule_Log(ctx, LOG_LEVEL_NOTICE, "init redis-auth success!");
return REDISMODULE_OK;
}

View File

@ -5,7 +5,8 @@
/* Error status return values. */
#define REDISMODULE_OK 0
#define REDISMODULE_ERR 1
#define LOG_LEVL_NOTICE "notice"
#define LOG_LEVEL_NOTICE "notice"
#define LOG_LEVEL_WARNING "warning"
/* *
* Redis Auth command