diff options
author | antirez <antirez@gmail.com> | 2018-09-27 11:39:58 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2018-09-27 11:44:16 +0200 |
commit | 7af83a0c11615d4c131ce0a81560450d7d7632c5 (patch) | |
tree | bcbd2116a92eb4734a19efa99ec5fcdaf270ddb7 | |
parent | 20f047965c1382219616e27afa51d72c0001895c (diff) | |
download | redis-7af83a0c11615d4c131ce0a81560450d7d7632c5.tar.gz |
Modules: Modules: dictionary API WIP #11: DictCompareC API.
-rw-r--r-- | src/module.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c index aec5c4df5..8295bd9b7 100644 --- a/src/module.c +++ b/src/module.c @@ -4568,6 +4568,24 @@ RedisModuleString *RM_DictPrev(RedisModuleCtx *ctx, RedisModuleDictIter *di, voi return RM_CreateString(ctx,key,keylen); } +/* Compare the element currently pointed by the iterator to the specified + * element given by key/keylen, according to the operator 'op' (the set of + * valid operators are the same valid for RedisModule_DictIteratorStart). + * If the comparision is successful the command returns REDISMODULE_OK + * otherwise REDISMODULE_ERR is returned. + * + * This is useful when we want to just emit a lexicographical range, so + * in the loop, as we iterate elements, we can also check if we are still + * on range. + * + * The function returne REDISMODULE_ERR if the iterator reached the + * end of elements condition as well. */ +int RM_DictCompareC(RedisModuleDictIter *di, const char *op, void *key, size_t keylen) { + if (raxEOF(&di->ri)) return REDISMODULE_ERR; + int res = raxCompare(&di->ri,op,key,keylen); + return res ? REDISMODULE_OK : REDISMODULE_ERR; +} + /* -------------------------------------------------------------------------- * Modules utility APIs * -------------------------------------------------------------------------- */ |