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

Function moduleDelKeyIfEmpty

src/module.cpp:588–609  ·  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

586 * The function returns 1 if the key value object is found empty and is
587 * deleted, otherwise 0 is returned. */
588int moduleDelKeyIfEmpty(RedisModuleKey *key) {
589 if (!(key->mode & REDISMODULE_WRITE) || key->value == NULL) return 0;
590 int isempty;
591 robj *o = key->value;
592
593 switch(o->type) {
594 case OBJ_LIST: isempty = listTypeLength(o) == 0; break;
595 case OBJ_SET: isempty = setTypeSize(o) == 0; break;
596 case OBJ_ZSET: isempty = zsetLength(o) == 0; break;
597 case OBJ_HASH: isempty = hashTypeLength(o) == 0; break;
598 case OBJ_STREAM: isempty = streamLength(o) == 0; break;
599 default: isempty = 0;
600 }
601
602 if (isempty) {
603 dbDelete(key->db,key->key);
604 key->value = NULL;
605 return 1;
606 } else {
607 return 0;
608 }
609}
610
611/* This function is used to set the thread local variables (serverTL) for
612 * arbitrary module threads. All incoming module threads share the same set of

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