struct redisCommand {
char *name;//命令名
redisCommandProc *proc;//命令执行函数
int arity; //参数个数,-N代表参数个数>=N,正数表示参数个数为N
char *sflags; //命令的sflags属性字符串
int flags; //从sflags获取的整数mask值
redisGetKeysProc *getkeys_proc;//获取key参数的可选函数,当下面3种情况都无法确定key参数的时候才需要使用该函数
int firstkey; //第一个key的位置,0表示没有key
int lastkey; //最后一个key的位置;负数计算为正数第(argc+lastkey)个
int keystep; //参数为 key,val,key,val,...格式,第一个和最后一个key之间的key跨步
long long microseconds;//命令从服务启动到现在的执行时间,单位:微秒
long long calls;//命令从服务启动到现在的执行的次数
};
//返回key的个数和位置
int *getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, int *numkeys) {
int j, i = 0, last, *keys;
UNUSED(argv);
if (cmd->firstkey == 0) {
*numkeys = 0;
return NULL;
}
last = cmd->lastkey;
if (last < 0) last = argc+last;
keys = zmalloc(sizeof(int)*((last - cmd->firstkey)+1));
for (j = cmd->firstkey; j <= last; j += cmd->keystep) {
if (j >= argc) {
/* Modules commands, and standard commands with a not fixed number
* of arguments (negative arity parameter) do not have dispatch
* time arity checks, so we need to handle the case where the user
* passed an invalid number of arguments here. In this case we
* return no keys and expect the command implementation to report
* an arity or syntax error. */
if (cmd->flags & CMD_MODULE || cmd->arity < 0) {
zfree(keys);
*numkeys = 0;
return NULL;
} else {
serverPanic("Redis built-in command declared keys positions not matching the arity requirements.");
}
}
keys[i++] = j;
}
*numkeys = i;
return keys;
}
版权声明:本文为m0_51787822原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。