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