Cleanup: remove zset reset function from RM_ZsetRangeStop().

This commit is contained in:
Yossi Gottlieb 2016-06-22 07:30:06 +03:00
parent a8e2034548
commit e22f3e40d5

View File

@ -163,7 +163,8 @@ void RM_CloseKey(RedisModuleKey *key);
void autoMemoryCollect(RedisModuleCtx *ctx); void autoMemoryCollect(RedisModuleCtx *ctx);
robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int *argcp, int *flags, va_list ap); robj **moduleCreateArgvFromUserFormat(const char *cmdname, const char *fmt, int *argcp, int *flags, va_list ap);
void moduleReplicateMultiIfNeeded(RedisModuleCtx *ctx); void moduleReplicateMultiIfNeeded(RedisModuleCtx *ctx);
void RM_ZsetRangeStop(RedisModuleKey *key); void RM_ZsetRangeStop(RedisModuleKey *kp);
static void zsetKeyReset(RedisModuleKey *key);
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
* Heap allocation raw functions * Heap allocation raw functions
@ -1047,8 +1048,7 @@ void *RM_OpenKey(RedisModuleCtx *ctx, robj *keyname, int mode) {
kp->value = value; kp->value = value;
kp->iter = NULL; kp->iter = NULL;
kp->mode = mode; kp->mode = mode;
kp->ztype = REDISMODULE_ZSET_RANGE_NONE; zsetKeyReset(kp);
RM_ZsetRangeStop(kp);
autoMemoryAdd(ctx,REDISMODULE_AM_KEY,kp); autoMemoryAdd(ctx,REDISMODULE_AM_KEY,kp);
return (void*)kp; return (void*)kp;
} }
@ -1434,19 +1434,25 @@ int RM_ZsetScore(RedisModuleKey *key, RedisModuleString *ele, double *score) {
* Key API for Sorted Set iterator * Key API for Sorted Set iterator
* -------------------------------------------------------------------------- */ * -------------------------------------------------------------------------- */
/* Stop a sorted set iteration. */ static void zsetKeyReset(RedisModuleKey *key)
void RM_ZsetRangeStop(RedisModuleKey *key) { {
/* Free resources if needed. */
if (key->ztype == REDISMODULE_ZSET_RANGE_LEX)
zslFreeLexRange(&key->zlrs);
/* Setup sensible values so that misused iteration API calls when an
* iterator is not active will result into something more sensible
* than crashing. */
key->ztype = REDISMODULE_ZSET_RANGE_NONE; key->ztype = REDISMODULE_ZSET_RANGE_NONE;
key->zcurrent = NULL; key->zcurrent = NULL;
key->zer = 1; key->zer = 1;
} }
/* Stop a sorted set iteration. */
void RM_ZsetRangeStop(RedisModuleKey *key) {
/* Free resources if needed. */
if (key->ztype == REDISMODULE_ZSET_RANGE_LEX) {
zslFreeLexRange(&key->zlrs);
}
/* Setup sensible values so that misused iteration API calls when an
* iterator is not active will result into something more sensible
* than crashing. */
zsetKeyReset(key);
}
/* Return the "End of range" flag value to signal the end of the iteration. */ /* Return the "End of range" flag value to signal the end of the iteration. */
int RM_ZsetRangeEndReached(RedisModuleKey *key) { int RM_ZsetRangeEndReached(RedisModuleKey *key) {
return key->zer; return key->zer;