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

Function moduleCreateEmptyKey

src/module.cpp:548–576  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

546 * 3. The specified type is unknown.
547 */
548int moduleCreateEmptyKey(RedisModuleKey *key, int type) {
549 robj *obj;
550
551 /* The key must be open for writing and non existing to proceed. */
552 if (!(key->mode & REDISMODULE_WRITE) || key->value)
553 return REDISMODULE_ERR;
554
555 switch(type) {
556 case REDISMODULE_KEYTYPE_LIST:
557 obj = createQuicklistObject();
558 quicklistSetOptions((quicklist*)obj->m_ptr, g_pserver->list_max_ziplist_size,
559 g_pserver->list_compress_depth);
560 break;
561 case REDISMODULE_KEYTYPE_ZSET:
562 obj = createZsetZiplistObject();
563 break;
564 case REDISMODULE_KEYTYPE_HASH:
565 obj = createHashObject();
566 break;
567 case REDISMODULE_KEYTYPE_STREAM:
568 obj = createStreamObject();
569 break;
570 default: return REDISMODULE_ERR;
571 }
572 dbAdd(key->db,key->key,obj);
573 key->value = obj;
574 moduleInitKeyTypeSpecific(key);
575 return REDISMODULE_OK;
576}
577
578/* This function is called in low-level API implementation functions in order
579 * to check if the value associated with the key remained empty after an

Callers 5

RM_ListPushFunction · 0.85
RM_ZsetAddFunction · 0.85
RM_ZsetIncrbyFunction · 0.85
RM_HashSetFunction · 0.85
RM_StreamAddFunction · 0.85

Calls 7

createQuicklistObjectFunction · 0.85
quicklistSetOptionsFunction · 0.85
createZsetZiplistObjectFunction · 0.85
createHashObjectFunction · 0.85
createStreamObjectFunction · 0.85
dbAddFunction · 0.85

Tested by

no test coverage detected