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

Function RM_SaveDataTypeToString

src/module.cpp:5118–5136  ·  view source on GitHub ↗

Encode a module data type 'mt' value 'data' into serialized form, and return it * as a newly allocated RedisModuleString. * * This call basically reuses the 'rdb_save' callback which module data types * implement in order to allow a module to arbitrarily serialize/de-serialize * keys, similar to how the Redis 'DUMP' and 'RESTORE' commands are implemented. */

Source from the content-addressed store, hash-verified

5116 * keys, similar to how the Redis 'DUMP' and 'RESTORE' commands are implemented.
5117 */
5118RedisModuleString *RM_SaveDataTypeToString(RedisModuleCtx *ctx, void *data, const moduleType *mt) {
5119 rio payload;
5120 RedisModuleIO io;
5121
5122 rioInitWithBuffer(&payload,sdsempty());
5123 moduleInitIOContext(io,(moduleType *)mt,&payload,NULL);
5124 mt->rdb_save(&io,data);
5125 if (io.ctx) {
5126 moduleFreeContext(io.ctx);
5127 zfree(io.ctx);
5128 }
5129 if (io.error) {
5130 return NULL;
5131 } else {
5132 robj *str = createObject(OBJ_STRING,payload.io.buffer.ptr);
5133 if (ctx != NULL) autoMemoryAdd(ctx,REDISMODULE_AM_STRING,str);
5134 return str;
5135 }
5136}
5137
5138/* --------------------------------------------------------------------------
5139 * ## AOF API for modules data types

Callers

nothing calls this directly

Calls 6

rioInitWithBufferFunction · 0.85
sdsemptyFunction · 0.85
moduleFreeContextFunction · 0.85
zfreeFunction · 0.85
createObjectFunction · 0.85
autoMemoryAddFunction · 0.85

Tested by

no test coverage detected