MCPcopy Create free account
hub / github.com/F-Stack/f-stack / moduleCreateEmptyKey

Function moduleCreateEmptyKey

app/redis-6.2.6/src/module.c:537–565  ·  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

535 * 3. The specified type is unknown.
536 */
537int 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

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