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

Function moduleDelKeyIfEmpty

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

This function is called in low-level API implementation functions in order * to check if the value associated with the key remained empty after an * operation that removed elements from an aggregate data type. * * If this happens, the key is deleted from the DB and the key object state * is set to the right one in order to be targeted again by write operations * possibly recreating the key i

Source from the content-addressed store, hash-verified

575 * The function returns 1 if the key value object is found empty and is
576 * deleted, otherwise 0 is returned. */
577int moduleDelKeyIfEmpty(RedisModuleKey *key) {
578 if (!(key->mode & REDISMODULE_WRITE) || key->value == NULL) return 0;
579 int isempty;
580 robj *o = key->value;
581
582 switch(o->type) {
583 case OBJ_LIST: isempty = listTypeLength(o) == 0; break;
584 case OBJ_SET: isempty = setTypeSize(o) == 0; break;
585 case OBJ_ZSET: isempty = zsetLength(o) == 0; break;
586 case OBJ_HASH: isempty = hashTypeLength(o) == 0; break;
587 case OBJ_STREAM: isempty = streamLength(o) == 0; break;
588 default: isempty = 0;
589 }
590
591 if (isempty) {
592 dbDelete(key->db,key->key);
593 key->value = NULL;
594 return 1;
595 } else {
596 return 0;
597 }
598}
599
600/* --------------------------------------------------------------------------
601 * Service API exported to modules

Callers 3

RM_ListPopFunction · 0.85
RM_ZsetRemFunction · 0.85
RM_HashSetFunction · 0.85

Calls 6

listTypeLengthFunction · 0.85
setTypeSizeFunction · 0.85
zsetLengthFunction · 0.85
hashTypeLengthFunction · 0.85
streamLengthFunction · 0.85
dbDeleteFunction · 0.85

Tested by

no test coverage detected