Create an empty key of the specified type. `key` must point to a key object * opened for writing where the `.value` member is set to NULL because the * key was found to be non existing. * * On success REDISMODULE_OK is returned and the key is populated with * the value of the specified type. The function fails and returns * REDISMODULE_ERR if: * * 1. The key is not open for writing. * 2.
| 535 | * 3. The specified type is unknown. |
| 536 | */ |
| 537 | int moduleCreateEmptyKey(RedisModuleKey *key, int type) { |
| 538 | robj *obj; |
| 539 | |
| 540 | /* The key must be open for writing and non existing to proceed. */ |
| 541 | if (!(key->mode & REDISMODULE_WRITE) || key->value) |
| 542 | return REDISMODULE_ERR; |
| 543 | |
| 544 | switch(type) { |
| 545 | case REDISMODULE_KEYTYPE_LIST: |
| 546 | obj = createQuicklistObject(); |
| 547 | quicklistSetOptions(obj->ptr, server.list_max_ziplist_size, |
| 548 | server.list_compress_depth); |
| 549 | break; |
| 550 | case REDISMODULE_KEYTYPE_ZSET: |
| 551 | obj = createZsetZiplistObject(); |
| 552 | break; |
| 553 | case REDISMODULE_KEYTYPE_HASH: |
| 554 | obj = createHashObject(); |
| 555 | break; |
| 556 | case REDISMODULE_KEYTYPE_STREAM: |
| 557 | obj = createStreamObject(); |
| 558 | break; |
| 559 | default: return REDISMODULE_ERR; |
| 560 | } |
| 561 | dbAdd(key->db,key->key,obj); |
| 562 | key->value = obj; |
| 563 | moduleInitKeyTypeSpecific(key); |
| 564 | return REDISMODULE_OK; |
| 565 | } |
| 566 | |
| 567 | /* This function is called in low-level API implementation functions in order |
| 568 | * to check if the value associated with the key remained empty after an |
no test coverage detected