Adds ArrayElementByPath

master
Itamar Haber 9 years ago committed by Dvir Volk
parent 546905bbfc
commit 16326d6e29

@ -193,4 +193,31 @@ int RMUtil_ParseArgsAfter(const char *token, RedisModuleString **argv, int argc,
va_end(ap);
return rc;
}
RedisModuleCallReply *RedisModule_CallReplyArrayElementByPath(
RedisModuleCallReply *rep, const char *path) {
if (rep == NULL) return NULL;
RedisModuleCallReply *ele = rep;
const char *s = path;
char *e;
long idx;
do {
errno = 0;
idx = strtol(s, &e, 10);
if ((errno == ERANGE && (idx == LONG_MAX || idx == LONG_MIN)) ||
(errno != 0 && idx == 0) ||
(REDISMODULE_REPLY_ARRAY != RedisModule_CallReplyType(ele)) ||
(s == e)) {
ele = NULL;
break;
}
s = e;
ele = RedisModule_CallReplyArrayElement(ele, idx - 1);
} while ((ele != NULL) && (*e != '\0'));
return ele;
}

@ -94,5 +94,13 @@ int RMUtilInfo_GetString(RMUtilInfo *info, const char *key, const char **str);
*/
int RMUtilInfo_GetDouble(RMUtilInfo *info, const char *key, double *d);
/*
* Returns a call reply array's element given by a space-delimited path. E.g.,
* the path "1 2 3" will return the 3rd element from the 2 element of the 1st
* element from an array (or NULL if not found)
*/
RedisModuleCallReply *RedisModule_CallReplyArrayElementByPath(
RedisModuleCallReply *rep, const char *path);
#endif

Loading…
Cancel
Save