summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-09-24 16:43:47 +0200
committerantirez <antirez@gmail.com>2018-09-24 16:43:47 +0200
commit3968550135f48b8caf3dee76fc50a5e4fe4af1fb (patch)
tree7ec8af0ed86fe5e5386d3a03f37b3ab289e90225
parent14b2f7b033ab7445146ba44940297cb97473aebe (diff)
downloadredis-3968550135f48b8caf3dee76fc50a5e4fe4af1fb.tar.gz
Modules: dictionary API work in progress #4: reseek API.
-rw-r--r--src/module.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/module.c b/src/module.c
index 456f83eaa..418777304 100644
--- a/src/module.c
+++ b/src/module.c
@@ -4443,17 +4443,36 @@ RedisModuleDictIter *RM_DictIteratorStartStr(RedisModuleDict *d, const char *op,
return RM_DictIteratorStart(d,op,key->ptr,sdslen(key->ptr));
}
-/* TODO
+/* Release the iterator created with RedisModule_DictIteratorStart(). This call
+ * is mandatory otherwise a memory leak is introduced in the module. */
+void RM_DictIteratorStop(RedisModuleDictIter *di) {
+ raxStop(&di->ri);
+ zfree(di);
+}
+
+/* After its creation with RedisModule_DictIteratorStart(), it is possible to
+ * change the currently selected element of the iterator by using this
+ * API call. The result based on the operator and key is exactly like
+ * the function RedisModule_DictIteratorStart(), however in this case the
+ * return value is just REDISMODULE_OK in case the seeked element was found,
+ * or REDISMODULE_ERR in case it was not possible to seek the specified
+ * element. It is possible to reseek an iterator as many times as you want. */
+int RM_DictIteratorReseek(RedisModuleDictIter *di, const char *op, void *key, size_t keylen) {
+ return raxSeek(&di->ri,op,key,keylen);
+}
- RM_DictIteratorStart();
- RM_DictIteratorStartStr();
- RM_DictIteratorReseek();
- RM_DictIteratorReseekStr();
+/* Like RedisModule_DictIteratorReseek() but takes the key as as a
+ * RedisModuleString. */
+int RM_DictIteratorReseekStr(RedisModuleDictIter *di, const char *op, RedisModuleString *key) {
+ return RM_DictIteratorReseek(di,op,key->ptr,sdslen(key->ptr));
+}
+
+/* TODO
RM_DictNext();
RM_DictPrev();
RM_DictNextStr();
RM_DictPrevStr();
- RM_DictIteratorStop();
+ Change the string API to make the context optional.
*/
/* --------------------------------------------------------------------------