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. */
| 5116 | * keys, similar to how the Redis 'DUMP' and 'RESTORE' commands are implemented. |
| 5117 | */ |
| 5118 | RedisModuleString *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 |
nothing calls this directly
no test coverage detected