Unverified Commit 2029976d authored by Valentino Geron's avatar Valentino Geron Committed by GitHub
Browse files

Optimization: moduleLoadString should try to create embedded string if not plain (#11050)



Before this change, if the module has an embedded string, then uses RedisModule_SaveString
and RedisModule_LoadString, the result would be a raw string instead of an embedded string.

Now the `RDB_LOAD_ENC` flag to `moduleLoadString` only affects integer encoding, but not
embedded strings (which still hold an sds in the robj ptr, so they're actually still raw strings for
anyone who reads them).
Co-authored-by: default avatarValentino Geron <valentino@redis.com>
parent 61451b02
...@@ -508,7 +508,6 @@ ssize_t rdbSaveStringObject(rio *rdb, robj *obj) { ...@@ -508,7 +508,6 @@ ssize_t rdbSaveStringObject(rio *rdb, robj *obj) {
* On I/O error NULL is returned. * On I/O error NULL is returned.
*/ */
void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) { void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
int encode = flags & RDB_LOAD_ENC;
int plain = flags & RDB_LOAD_PLAIN; int plain = flags & RDB_LOAD_PLAIN;
int sds = flags & RDB_LOAD_SDS; int sds = flags & RDB_LOAD_SDS;
int isencoded; int isencoded;
...@@ -547,8 +546,7 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) { ...@@ -547,8 +546,7 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
} }
return buf; return buf;
} else { } else {
robj *o = encode ? tryCreateStringObject(SDS_NOINIT,len) : robj *o = tryCreateStringObject(SDS_NOINIT,len);
tryCreateRawStringObject(SDS_NOINIT,len);
if (!o) { if (!o) {
serverLog(isRestoreContext()? LL_VERBOSE: LL_WARNING, "rdbGenericLoadStringObject failed allocating %llu bytes", len); serverLog(isRestoreContext()? LL_VERBOSE: LL_WARNING, "rdbGenericLoadStringObject failed allocating %llu bytes", len);
return NULL; return NULL;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment