mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
Modules: a few fixes for the zset iterator.
This commit is contained in:
parent
33e1231e53
commit
5bf5fd24c6
@ -1366,7 +1366,7 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
next = saved_next;
|
next = saved_next;
|
||||||
} else if (key->ztype == REDISMODULE_ZSET_RANGE_SCORE) {
|
} else if (key->ztype == REDISMODULE_ZSET_RANGE_LEX) {
|
||||||
if (!zzlLexValueLteMax(next,&key->zlrs)) {
|
if (!zzlLexValueLteMax(next,&key->zlrs)) {
|
||||||
key->zer = 1;
|
key->zer = 1;
|
||||||
return 0;
|
return 0;
|
||||||
@ -1429,7 +1429,7 @@ int RM_ZsetRangePrev(RedisModuleKey *key) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
prev = saved_prev;
|
prev = saved_prev;
|
||||||
} else if (key->ztype == REDISMODULE_ZSET_RANGE_SCORE) {
|
} else if (key->ztype == REDISMODULE_ZSET_RANGE_LEX) {
|
||||||
if (!zzlLexValueGteMin(prev,&key->zlrs)) {
|
if (!zzlLexValueGteMin(prev,&key->zlrs)) {
|
||||||
key->zer = 1;
|
key->zer = 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -387,7 +387,7 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
|||||||
* The command will return all the sorted set items that are lexicographically
|
* The command will return all the sorted set items that are lexicographically
|
||||||
* between the specified range (using the same format as ZRANGEBYLEX)
|
* between the specified range (using the same format as ZRANGEBYLEX)
|
||||||
* and having an age between min_age and max_age. */
|
* 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. */
|
RedisModule_AutoMemory(ctx); /* Use automatic memory management. */
|
||||||
|
|
||||||
if (argc != 6) return RedisModule_WrongArity(ctx);
|
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);
|
return RedisModule_ReplyWithError(ctx,REDISMODULE_ERRORMSG_WRONGTYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_ARRAY_LEN);
|
if (RedisModule_ZsetFirstInLexRange(key,argv[2],argv[3]) != REDISMODULE_OK) {
|
||||||
RedisModule_ZsetFirstInLexRange(key,argv[2],argv[3]);
|
return RedisModule_ReplyWithError(ctx,"invalid range");
|
||||||
|
}
|
||||||
|
|
||||||
int arraylen = 0;
|
int arraylen = 0;
|
||||||
|
RedisModule_ReplyWithArray(ctx,REDISMODULE_POSTPONED_ARRAY_LEN);
|
||||||
while(!RedisModule_ZsetRangeEndReached(key)) {
|
while(!RedisModule_ZsetRangeEndReached(key)) {
|
||||||
double score;
|
double score;
|
||||||
RedisModuleString *ele = RedisModule_ZsetRangeCurrentElement(key,&score);
|
RedisModuleString *ele = RedisModule_ZsetRangeCurrentElement(key,&score);
|
||||||
@ -410,7 +413,7 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
|
|||||||
arraylen++;
|
arraylen++;
|
||||||
}
|
}
|
||||||
RedisModule_ZsetRangeStop(key);
|
RedisModule_ZsetRangeStop(key);
|
||||||
RedisModule_SetArrayLength(ctx,arraylen);
|
RedisModule_ReplySetArrayLength(ctx,arraylen);
|
||||||
RedisModule_CloseKey(key);
|
RedisModule_CloseKey(key);
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
@ -473,5 +476,9 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) {
|
|||||||
HelloZsumRange_RedisCommand) == REDISMODULE_ERR)
|
HelloZsumRange_RedisCommand) == REDISMODULE_ERR)
|
||||||
return REDISMODULE_ERR;
|
return REDISMODULE_ERR;
|
||||||
|
|
||||||
|
if (RedisModule_CreateCommand(ctx,"hello.lexrange",
|
||||||
|
HelloLexRange_RedisCommand) == REDISMODULE_ERR)
|
||||||
|
return REDISMODULE_ERR;
|
||||||
|
|
||||||
return REDISMODULE_OK;
|
return REDISMODULE_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user