MCPcopy Create free account
hub / github.com/F-Stack/f-stack / RM_ZsetIncrby

Function RM_ZsetIncrby

app/redis-6.2.6/src/module.c:2679–2692  ·  view source on GitHub ↗

This function works exactly like RM_ZsetAdd(), but instead of setting * a new score, the score of the existing element is incremented, or if the * element does not already exist, it is added assuming the old score was * zero. * * The input and output flags, and the return value, have the same exact * meaning, with the only difference that this function will return * REDISMODULE_ERR even whe

Source from the content-addressed store, hash-verified

2677 * with the new score of the element after the increment, if no error
2678 * is returned. */
2679int RM_ZsetIncrby(RedisModuleKey *key, double score, RedisModuleString *ele, int *flagsptr, double *newscore) {
2680 int in_flags = 0, out_flags = 0;
2681 if (!(key->mode & REDISMODULE_WRITE)) return REDISMODULE_ERR;
2682 if (key->value && key->value->type != OBJ_ZSET) return REDISMODULE_ERR;
2683 if (key->value == NULL) moduleCreateEmptyKey(key,REDISMODULE_KEYTYPE_ZSET);
2684 if (flagsptr) in_flags = moduleZsetAddFlagsToCoreFlags(*flagsptr);
2685 in_flags |= ZADD_IN_INCR;
2686 if (zsetAdd(key->value,score,ele->ptr,in_flags,&out_flags,newscore) == 0) {
2687 if (flagsptr) *flagsptr = 0;
2688 return REDISMODULE_ERR;
2689 }
2690 if (flagsptr) *flagsptr = moduleZsetAddFlagsFromCoreFlags(out_flags);
2691 return REDISMODULE_OK;
2692}
2693
2694/* Remove the specified element from the sorted set.
2695 * The function returns REDISMODULE_OK on success, and REDISMODULE_ERR

Callers

nothing calls this directly

Calls 4

moduleCreateEmptyKeyFunction · 0.85
zsetAddFunction · 0.85

Tested by

no test coverage detected