MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / commandFlagsFromString

Function commandFlagsFromString

src/module.cpp:817–845  ·  view source on GitHub ↗

Helper for RM_CreateCommand(). Turns a string representing command * flags into the command flags used by the Redis core. * * It returns the set of flags, or -1 if unknown flags are found. */

Source from the content-addressed store, hash-verified

815 *
816 * It returns the set of flags, or -1 if unknown flags are found. */
817int64_t commandFlagsFromString(char *s) {
818 int count, j;
819 int64_t flags = 0;
820 sds *tokens = sdssplitlen(s,strlen(s)," ",1,&count);
821 for (j = 0; j < count; j++) {
822 char *t = tokens[j];
823 if (!strcasecmp(t,"write")) flags |= CMD_WRITE;
824 else if (!strcasecmp(t,"readonly")) flags |= CMD_READONLY;
825 else if (!strcasecmp(t,"admin")) flags |= CMD_ADMIN;
826 else if (!strcasecmp(t,"deny-oom")) flags |= CMD_DENYOOM;
827 else if (!strcasecmp(t,"deny-script")) flags |= CMD_NOSCRIPT;
828 else if (!strcasecmp(t,"allow-loading")) flags |= CMD_LOADING;
829 else if (!strcasecmp(t,"pubsub")) flags |= CMD_PUBSUB;
830 else if (!strcasecmp(t,"random")) flags |= CMD_RANDOM;
831 else if (!strcasecmp(t,"allow-stale")) flags |= CMD_STALE;
832 else if (!strcasecmp(t,"no-monitor")) flags |= CMD_SKIP_MONITOR;
833 else if (!strcasecmp(t,"no-slowlog")) flags |= CMD_SKIP_SLOWLOG;
834 else if (!strcasecmp(t,"fast")) flags |= CMD_FAST;
835 else if (!strcasecmp(t,"no-auth")) flags |= CMD_NO_AUTH;
836 else if (!strcasecmp(t,"may-replicate")) flags |= CMD_MAY_REPLICATE;
837 else if (!strcasecmp(t,"getkeys-api")) flags |= CMD_MODULE_GETKEYS;
838 else if (!strcasecmp(t,"no-cluster")) flags |= CMD_MODULE_NO_CLUSTER;
839 else if (!strcasecmp(t,"async")) flags |= CMD_ASYNC_OK;
840 else break;
841 }
842 sdsfreesplitres(tokens,count);
843 if (j != count) return -1; /* Some token not processed correctly. */
844 return flags;
845}
846
847/* Register a new command in the Redis server, that will be handled by
848 * calling the function pointer 'func' using the RedisModule calling

Callers 1

RM_CreateCommandFunction · 0.85

Calls 2

sdssplitlenFunction · 0.85
sdsfreesplitresFunction · 0.85

Tested by

no test coverage detected