diff options
author | zhaozhao.zz <zhaozhao.zz@alibaba-inc.com> | 2019-02-14 00:12:10 +0800 |
---|---|---|
committer | zhaozhao.zz <zhaozhao.zz@alibaba-inc.com> | 2019-02-14 00:13:01 +0800 |
commit | 14507457a08acb6886dc8ae37dba8511ffc18939 (patch) | |
tree | d9cf125046250f29db5aba08d9082876f4bece63 | |
parent | a65094dae811770c904f9ec5bb54c41caf5d9f66 (diff) | |
download | redis-14507457a08acb6886dc8ae37dba8511ffc18939.tar.gz |
ACL: show categories in COMMAND reply
Adding another new filed categories at the end of
command reply, it's easy to read and distinguish
flags and categories, also compatible with old format.
-rw-r--r-- | src/acl.c | 12 | ||||
-rw-r--r-- | src/server.c | 6 | ||||
-rw-r--r-- | src/server.h | 1 |
3 files changed, 17 insertions, 2 deletions
@@ -1480,3 +1480,15 @@ NULL addReplySubcommandSyntaxError(c); } } + +void addReplyCommandCategories(client *c, struct redisCommand *cmd) { + int flagcount = 0; + void *flaglen = addReplyDeferredLen(c); + for (int j = 0; ACLCommandCategories[j].flag != 0; j++) { + if (cmd->flags & ACLCommandCategories[j].flag) { + addReplyStatusFormat(c, "@%s", ACLCommandCategories[j].name); + flagcount++; + } + } + setDeferredSetLen(c, flaglen, flagcount); +} diff --git a/src/server.c b/src/server.c index 1a6c277e1..7d78efcab 100644 --- a/src/server.c +++ b/src/server.c @@ -3698,8 +3698,8 @@ void addReplyCommand(client *c, struct redisCommand *cmd) { if (!cmd) { addReplyNull(c); } else { - /* We are adding: command name, arg count, flags, first, last, offset */ - addReplyArrayLen(c, 6); + /* We are adding: command name, arg count, flags, first, last, offset, categories */ + addReplyArrayLen(c, 7); addReplyBulkCString(c, cmd->name); addReplyLongLong(c, cmd->arity); @@ -3729,6 +3729,8 @@ void addReplyCommand(client *c, struct redisCommand *cmd) { addReplyLongLong(c, cmd->firstkey); addReplyLongLong(c, cmd->lastkey); addReplyLongLong(c, cmd->keystep); + + addReplyCommandCategories(c,cmd); } } diff --git a/src/server.h b/src/server.h index a396e1cf7..994952654 100644 --- a/src/server.h +++ b/src/server.h @@ -1748,6 +1748,7 @@ char *ACLSetUserStringError(void); int ACLLoadConfiguredUsers(void); sds ACLDescribeUser(user *u); void ACLLoadUsersAtStartup(void); +void addReplyCommandCategories(client *c, struct redisCommand *cmd); /* Sorted sets data type */ |