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
| 586 | * The function returns 1 if the key value object is found empty and is |
| 587 | * deleted, otherwise 0 is returned. */ |
| 588 | int 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 |
no test coverage detected