summaryrefslogtreecommitdiff
path: root/src/modules/helloworld.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-04-25 10:39:02 +0200
committerantirez <antirez@gmail.com>2016-05-10 06:40:09 +0200
commit5bf5fd24c6054ccecb068f2a74c9c84aa2f2d79f (patch)
tree54beab02bcfaf410cdf0fc63b85565303562369a /src/modules/helloworld.c
parent33e1231e533168915f006f2b39751b7013247a2d (diff)
downloadredis-5bf5fd24c6054ccecb068f2a74c9c84aa2f2d79f.tar.gz
Modules: a few fixes for the zset iterator.
Diffstat (limited to 'src/modules/helloworld.c')
-rw-r--r--src/modules/helloworld.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/modules/helloworld.c b/src/modules/helloworld.c
index 785d401b2..31a078b0a 100644
--- a/src/modules/helloworld.c
+++ b/src/modules/helloworld.c
@@ -387,7 +387,7 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
* The command will return all the sorted set items that are lexicographically
* between the specified range (using the same format as ZRANGEBYLEX)
* and having an age between min_age and max_age. */
-int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
+int HelloLexRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
RedisModule_AutoMemory(ctx); /* Use automatic memory management. */
if (argc != 6) return RedisModule_WrongArity(ctx);
@@ -398,9 +398,12 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
}
- RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_ARRAY_LEN);
- RedisModule_ZsetFirstInLexRange(key,argv[2],argv[3]);
+ if (RedisModule_ZsetFirstInLexRange(key,argv[2],argv[3]) != REDISMODULE_OK) {
+ return RedisModule_ReplyWithError(ctx,"invalid range");
+ }
+
int arraylen = 0;
+ RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_ARRAY_LEN);
while(!RedisModule_ZsetRangeEndReached(key)) {
double score;
RedisModuleString *ele = RedisModule_ZsetRangeCurrentElement(key,&score);
@@ -410,7 +413,7 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
arraylen++;
}
RedisModule_ZsetRangeStop(key);
- RedisModule_SetArrayLength(ctx,arraylen);
+ RedisModule_ReplySetArrayLength(ctx,arraylen);
RedisModule_CloseKey(key);
return REDISMODULE_OK;
}
@@ -473,5 +476,9 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) {
HelloZsumRange_RedisCommand) == REDISMODULE_ERR)
return REDISMODULE_ERR;
+ if (RedisModule_CreateCommand(ctx,"hello.lexrange",
+ HelloLexRange_RedisCommand) == REDISMODULE_ERR)
+ return REDISMODULE_ERR;
+
return REDISMODULE_OK;
}