From 7af83a0c11615d4c131ce0a81560450d7d7632c5 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 27 Sep 2018 11:39:58 +0200 Subject: [PATCH] Modules: Modules: dictionary API WIP #11: DictCompareC API. --- src/module.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/module.c b/src/module.c index aec5c4df..8295bd9b 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 * -------------------------------------------------------------------------- */