Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
82d194c1
Commit
82d194c1
authored
Jan 22, 2019
by
antirez
Browse files
ACL: populate command table with new flags.
parent
9e4fb96c
Changes
1
Show whitespace changes
Inline
Side-by-side
src/server.c
View file @
82d194c1
...
@@ -814,7 +814,7 @@ struct redisCommand redisCommandTable[] = {
...
@@ -814,7 +814,7 @@ struct redisCommand redisCommandTable[] = {
0,NULL,1,1,1,0,0,0},
0,NULL,1,1,1,0,0,0},
{"wait",waitCommand,3,
{"wait",waitCommand,3,
"noscript"
,
"no
-
script",
0,NULL,0,0,0,0,0,0},
0,NULL,0,0,0,0,0,0},
{"command",commandCommand,0,
{"command",commandCommand,0,
...
@@ -2816,6 +2816,41 @@ void initServer(void) {
...
@@ -2816,6 +2816,41 @@ void initServer(void) {
server.initial_memory_usage = zmalloc_used_memory();
server.initial_memory_usage = zmalloc_used_memory();
}
}
/* Parse the flags string description 'strflags' and set them to the
* command 'c'. If the flags are all valid C_OK is returned, otherwise
* C_ERR is returned (yet the recognized flags are set in the command). */
int populateCommandTableParseFlags(struct redisCommand *c, char *strflags) {
int argc;
sds *argv;
/* Split the line into arguments for processing. */
argv = sdssplitargs(strflags,&argc);
if (argv == NULL) return C_ERR;
for (int j = 0; j < argc; j++) {
char *flag = argv[j];
if (!strcasecmp(flag,"write")) c->flags |= CMD_WRITE;
else if (!strcasecmp(flag,"read-only")) c->flags |= CMD_READONLY;
else if (!strcasecmp(flag,"use-memory")) c->flags |= CMD_DENYOOM;
else if (!strcasecmp(flag,"admin")) c->flags |= CMD_ADMIN;
else if (!strcasecmp(flag,"pub-sub")) c->flags |= CMD_PUBSUB;
else if (!strcasecmp(flag,"no-script")) c->flags |= CMD_NOSCRIPT;
else if (!strcasecmp(flag,"random")) c->flags |= CMD_RANDOM;
else if (!strcasecmp(flag,"to-sort")) c->flags |= CMD_SORT_FOR_SCRIPT;
else if (!strcasecmp(flag,"ok-loading")) c->flags |= CMD_LOADING;
else if (!strcasecmp(flag,"ok-stale")) c->flags |= CMD_STALE;
else if (!strcasecmp(flag,"no-monitor")) c->flags |= CMD_SKIP_MONITOR;
else if (!strcasecmp(flag,"cluster-asking")) c->flags |= CMD_ASKING;
else if (!strcasecmp(flag,"fast")) c->flags |= CMD_FAST;
else {
sdsfreesplitres(argv,argc);
return C_ERR;
}
}
sdsfreesplitres(argv,argc);
return C_OK;
}
/* Populates the Redis Command Table starting from the hard coded list
/* Populates the Redis Command Table starting from the hard coded list
* we have on top of redis.c file. */
* we have on top of redis.c file. */
void populateCommandTable(void) {
void populateCommandTable(void) {
...
@@ -2824,30 +2859,12 @@ void populateCommandTable(void) {
...
@@ -2824,30 +2859,12 @@ void populateCommandTable(void) {
for (j = 0; j < numcommands; j++) {
for (j = 0; j < numcommands; j++) {
struct redisCommand *c = redisCommandTable+j;
struct redisCommand *c = redisCommandTable+j;
char
*
f
=
c
->
sflags
;
int retval1, retval2;
int retval1, retval2;
/* Translate the command string flags description into an actual
/* Translate the command string flags description into an actual
* set of flags. */
* set of flags. */
while
(
*
f
!=
'\0'
)
{
if (populateCommandTableParseFlags(c,c->sflags) == C_ERR)
switch
(
*
f
)
{
serverPanic("Unsupported command flag");
case
'w'
:
c
->
flags
|=
CMD_WRITE
;
break
;
case
'r'
:
c
->
flags
|=
CMD_READONLY
;
break
;
case
'm'
:
c
->
flags
|=
CMD_DENYOOM
;
break
;
case
'a'
:
c
->
flags
|=
CMD_ADMIN
;
break
;
case
'p'
:
c
->
flags
|=
CMD_PUBSUB
;
break
;
case
's'
:
c
->
flags
|=
CMD_NOSCRIPT
;
break
;
case
'R'
:
c
->
flags
|=
CMD_RANDOM
;
break
;
case
'S'
:
c
->
flags
|=
CMD_SORT_FOR_SCRIPT
;
break
;
case
'l'
:
c
->
flags
|=
CMD_LOADING
;
break
;
case
't'
:
c
->
flags
|=
CMD_STALE
;
break
;
case
'M'
:
c
->
flags
|=
CMD_SKIP_MONITOR
;
break
;
case
'k'
:
c
->
flags
|=
CMD_ASKING
;
break
;
case
'F'
:
c
->
flags
|=
CMD_FAST
;
break
;
default:
serverPanic
(
"Unsupported command flag"
);
break
;
}
f
++
;
}
c->id = ACLGetCommandID(c->name); /* Assign the ID used for ACL. */
c->id = ACLGetCommandID(c->name); /* Assign the ID used for ACL. */
retval1 = dictAdd(server.commands, sdsnew(c->name), c);
retval1 = dictAdd(server.commands, sdsnew(c->name), c);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment