summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHanna Fadida <hanna.fadida@redislabs.com>2021-09-30 11:21:32 +0300
committerGitHub <noreply@github.com>2021-09-30 11:21:32 +0300
commitffafb434fb50b5697d1aa35342721eaa5f13e0eb (patch)
tree8dc146d30cac4174379aba9b463b24d4f31380d4 /src
parentd715655f16ef1b0ebbde35cd87a344cdd6dd0789 (diff)
downloadredis-ffafb434fb50b5697d1aa35342721eaa5f13e0eb.tar.gz
Modules: add RM_LoadDataTypeFromStringEncver (#9537)
adding an advanced api to enable loading data that was sereialized with a specific encoding version
Diffstat (limited to 'src')
-rw-r--r--src/module.c16
-rw-r--r--src/redismodule.h2
2 files changed, 14 insertions, 4 deletions
diff --git a/src/module.c b/src/module.c
index eeda8573d..a5d5afe40 100644
--- a/src/module.c
+++ b/src/module.c
@@ -5722,8 +5722,8 @@ void RM_DigestEndSequence(RedisModuleDigest *md) {
memset(md->o,0,sizeof(md->o));
}
-/* Decode a serialized representation of a module data type 'mt' from string
- * 'str' and return a newly allocated value, or NULL if decoding failed.
+/* Decode a serialized representation of a module data type 'mt', in a specific encoding version 'encver'
+ * from string 'str' and return a newly allocated value, or NULL if decoding failed.
*
* This call basically reuses the 'rdb_load' callback which module data types
* implement in order to allow a module to arbitrarily serialize/de-serialize
@@ -5736,7 +5736,7 @@ void RM_DigestEndSequence(RedisModuleDigest *md) {
* If this is NOT done, Redis will handle corrupted (or just truncated) serialized
* data by producing an error message and terminating the process.
*/
-void *RM_LoadDataTypeFromString(const RedisModuleString *str, const moduleType *mt) {
+void *RM_LoadDataTypeFromStringEncver(const RedisModuleString *str, const moduleType *mt, int encver) {
rio payload;
RedisModuleIO io;
void *ret;
@@ -5748,7 +5748,7 @@ void *RM_LoadDataTypeFromString(const RedisModuleString *str, const moduleType *
* need to make sure we read the same.
*/
io.ver = 2;
- ret = mt->rdb_load(&io,0);
+ ret = mt->rdb_load(&io,encver);
if (io.ctx) {
moduleFreeContext(io.ctx);
zfree(io.ctx);
@@ -5756,6 +5756,13 @@ void *RM_LoadDataTypeFromString(const RedisModuleString *str, const moduleType *
return ret;
}
+/* Similar to RM_LoadDataTypeFromStringEncver, original version of the API, kept
+ * for backward compatibility.
+ */
+void *RM_LoadDataTypeFromString(const RedisModuleString *str, const moduleType *mt) {
+ return RM_LoadDataTypeFromStringEncver(str, mt, 0);
+}
+
/* Encode a module data type 'mt' value 'data' into serialized form, and return it
* as a newly allocated RedisModuleString.
*
@@ -10352,6 +10359,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API(LoadLongDouble);
REGISTER_API(SaveDataTypeToString);
REGISTER_API(LoadDataTypeFromString);
+ REGISTER_API(LoadDataTypeFromStringEncver);
REGISTER_API(EmitAOF);
REGISTER_API(Log);
REGISTER_API(LogIOError);
diff --git a/src/redismodule.h b/src/redismodule.h
index acfa72d0a..586b0c6ee 100644
--- a/src/redismodule.h
+++ b/src/redismodule.h
@@ -746,6 +746,7 @@ REDISMODULE_API float (*RedisModule_LoadFloat)(RedisModuleIO *io) REDISMODULE_AT
REDISMODULE_API void (*RedisModule_SaveLongDouble)(RedisModuleIO *io, long double value) REDISMODULE_ATTR;
REDISMODULE_API long double (*RedisModule_LoadLongDouble)(RedisModuleIO *io) REDISMODULE_ATTR;
REDISMODULE_API void * (*RedisModule_LoadDataTypeFromString)(const RedisModuleString *str, const RedisModuleType *mt) REDISMODULE_ATTR;
+REDISMODULE_API void * (*RedisModule_LoadDataTypeFromStringEncver)(const RedisModuleString *str, const RedisModuleType *mt, int encver) REDISMODULE_ATTR;
REDISMODULE_API RedisModuleString * (*RedisModule_SaveDataTypeToString)(RedisModuleCtx *ctx, void *data, const RedisModuleType *mt) REDISMODULE_ATTR;
REDISMODULE_API void (*RedisModule_Log)(RedisModuleCtx *ctx, const char *level, const char *fmt, ...) REDISMODULE_ATTR REDISMODULE_ATTR_PRINTF(3,4);
REDISMODULE_API void (*RedisModule_LogIOError)(RedisModuleIO *io, const char *levelstr, const char *fmt, ...) REDISMODULE_ATTR REDISMODULE_ATTR_PRINTF(3,4);
@@ -1062,6 +1063,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API(LoadLongDouble);
REDISMODULE_GET_API(SaveDataTypeToString);
REDISMODULE_GET_API(LoadDataTypeFromString);
+ REDISMODULE_GET_API(LoadDataTypeFromStringEncver);
REDISMODULE_GET_API(EmitAOF);
REDISMODULE_GET_API(Log);
REDISMODULE_GET_API(LogIOError);