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

Function RM_CreateDataType

src/module.cpp:4606–4658  ·  view source on GitHub ↗

Register a new data type exported by the module. The parameters are the * following. Please for in depth documentation check the modules API * documentation, especially https://redis.io/topics/modules-native-types. * * * **name**: A 9 characters data type name that MUST be unique in the Redis * Modules ecosystem. Be creative... and there will be no collisions. Use * the charset A-Z a-z 9

Source from the content-addressed store, hash-verified

4604 * }
4605 */
4606moduleType *RM_CreateDataType(RedisModuleCtx *ctx, const char *name, int encver, void *typemethods_ptr) {
4607 uint64_t id = moduleTypeEncodeId(name,encver);
4608 if (id == 0) return NULL;
4609 if (moduleTypeLookupModuleByName(name) != NULL) return NULL;
4610
4611 long typemethods_version = ((long*)typemethods_ptr)[0];
4612 if (typemethods_version == 0) return NULL;
4613
4614 struct typemethods {
4615 uint64_t version;
4616 moduleTypeLoadFunc rdb_load;
4617 moduleTypeSaveFunc rdb_save;
4618 moduleTypeRewriteFunc aof_rewrite;
4619 moduleTypeMemUsageFunc mem_usage;
4620 moduleTypeDigestFunc digest;
4621 moduleTypeFreeFunc free;
4622 struct {
4623 moduleTypeAuxLoadFunc aux_load;
4624 moduleTypeAuxSaveFunc aux_save;
4625 int aux_save_triggers;
4626 } v2;
4627 struct {
4628 moduleTypeFreeEffortFunc free_effort;
4629 moduleTypeUnlinkFunc unlink;
4630 moduleTypeCopyFunc copy;
4631 moduleTypeDefragFunc defrag;
4632 } v3;
4633 } *tms = (struct typemethods*) typemethods_ptr;
4634
4635 moduleType *mt = (moduleType*)zcalloc(sizeof(*mt), MALLOC_LOCAL);
4636 mt->id = id;
4637 mt->module = ctx->module;
4638 mt->rdb_load = tms->rdb_load;
4639 mt->rdb_save = tms->rdb_save;
4640 mt->aof_rewrite = tms->aof_rewrite;
4641 mt->mem_usage = tms->mem_usage;
4642 mt->digest = tms->digest;
4643 mt->free = tms->free;
4644 if (tms->version >= 2) {
4645 mt->aux_load = tms->v2.aux_load;
4646 mt->aux_save = tms->v2.aux_save;
4647 mt->aux_save_triggers = tms->v2.aux_save_triggers;
4648 }
4649 if (tms->version >= 3) {
4650 mt->free_effort = tms->v3.free_effort;
4651 mt->unlink = tms->v3.unlink;
4652 mt->copy = tms->v3.copy;
4653 mt->defrag = tms->v3.defrag;
4654 }
4655 memcpy(mt->name,name,sizeof(mt->name));
4656 listAddNodeTail(ctx->module->types,mt);
4657 return mt;
4658}
4659
4660/* If the key is open for writing, set the specified module type object
4661 * as the value of the key, deleting the old value if any.

Callers

nothing calls this directly

Calls 4

moduleTypeEncodeIdFunction · 0.85
zcallocFunction · 0.85
listAddNodeTailFunction · 0.85

Tested by

no test coverage detected