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: Valentino Geron <valentino@redis.com>
This commit is contained in:
Valentino Geron 2022-07-31 17:29:59 +03:00 committed by GitHub
parent 61451b02cb
commit 2029976dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -508,7 +508,6 @@ ssize_t rdbSaveStringObject(rio *rdb, robj *obj) {
* On I/O error NULL is returned.
*/
void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
int encode = flags & RDB_LOAD_ENC;
int plain = flags & RDB_LOAD_PLAIN;
int sds = flags & RDB_LOAD_SDS;
int isencoded;
@ -547,8 +546,7 @@ void *rdbGenericLoadStringObject(rio *rdb, int flags, size_t *lenptr) {
}
return buf;
} else {
robj *o = encode ? tryCreateStringObject(SDS_NOINIT,len) :
tryCreateRawStringObject(SDS_NOINIT,len);
robj *o = tryCreateStringObject(SDS_NOINIT,len);
if (!o) {
serverLog(isRestoreContext()? LL_VERBOSE: LL_WARNING, "rdbGenericLoadStringObject failed allocating %llu bytes", len);
return NULL;