MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_ZsetAdd

Function RM_ZsetAdd

src/module.cpp:2740–2752  ·  view source on GitHub ↗

Add a new element into a sorted set, with the specified 'score'. * If the element already exists, the score is updated. * * A new sorted set is created at value if the key is an empty open key * setup for writing. * * Additional flags can be passed to the function via a pointer, the flags * are both used to receive input and to communicate state when the function * returns. 'flagsptr' can

Source from the content-addressed store, hash-verified

2738 * * 'score' double value is not a number (NaN).
2739 */
2740int RM_ZsetAdd(RedisModuleKey *key, double score, RedisModuleString *ele, int *flagsptr) {
2741 int in_flags = 0, out_flags = 0;
2742 if (!(key->mode & REDISMODULE_WRITE)) return REDISMODULE_ERR;
2743 if (key->value && key->value->type != OBJ_ZSET) return REDISMODULE_ERR;
2744 if (key->value == NULL) moduleCreateEmptyKey(key,REDISMODULE_KEYTYPE_ZSET);
2745 if (flagsptr) in_flags = moduleZsetAddFlagsToCoreFlags(*flagsptr);
2746 if (zsetAdd(key->value,score,szFromObj(ele),in_flags,&out_flags,NULL) == 0) {
2747 if (flagsptr) *flagsptr = 0;
2748 return REDISMODULE_ERR;
2749 }
2750 if (flagsptr) *flagsptr = moduleZsetAddFlagsFromCoreFlags(out_flags);
2751 return REDISMODULE_OK;
2752}
2753
2754/* This function works exactly like RM_ZsetAdd(), but instead of setting
2755 * a new score, the score of the existing element is incremented, or if the

Callers

nothing calls this directly

Calls 5

moduleCreateEmptyKeyFunction · 0.85
zsetAddFunction · 0.85
szFromObjFunction · 0.85

Tested by

no test coverage detected