diff --git a/src/object.c b/src/object.c index 8a911d334..6e5e94769 100644 --- a/src/object.c +++ b/src/object.c @@ -629,7 +629,7 @@ void trimStringObjectIfNeeded(robj *o, int trim_small_values) { } /* Try to encode a string object in order to save space */ -robj *tryObjectEncoding(robj *o) { +robj *tryObjectEncodingEx(robj *o, int try_trim) { long value; sds s = o->ptr; size_t len; @@ -694,12 +694,17 @@ robj *tryObjectEncoding(robj *o) { /* We can't encode the object... * Do the last try, and at least optimize the SDS string inside */ - trimStringObjectIfNeeded(o, 0); + if (try_trim) + trimStringObjectIfNeeded(o, 0); /* Return the original object. */ return o; } +robj *tryObjectEncoding(robj *o) { + return tryObjectEncodingEx(o, 1); +} + /* Get a decoded version of an encoded object (returned as a new object). * If the object is already raw-encoded just increment the ref count. */ robj *getDecodedObject(robj *o) { diff --git a/src/rdb.c b/src/rdb.c index c52d8faf7..71a49e99b 100644 --- a/src/rdb.c +++ b/src/rdb.c @@ -1844,7 +1844,7 @@ robj *rdbLoadObject(int rdbtype, rio *rdb, sds key, int dbid, int *error) { if (rdbtype == RDB_TYPE_STRING) { /* Read string value */ if ((o = rdbLoadEncodedStringObject(rdb)) == NULL) return NULL; - o = tryObjectEncoding(o); + o = tryObjectEncodingEx(o, 0); } else if (rdbtype == RDB_TYPE_LIST) { /* Read list value */ if ((len = rdbLoadLen(rdb,NULL)) == RDB_LENERR) return NULL; diff --git a/src/server.h b/src/server.h index b0cf27927..755a79dae 100644 --- a/src/server.h +++ b/src/server.h @@ -2738,6 +2738,7 @@ robj *dupStringObject(const robj *o); int isSdsRepresentableAsLongLong(sds s, long long *llval); int isObjectRepresentableAsLongLong(robj *o, long long *llongval); robj *tryObjectEncoding(robj *o); +robj *tryObjectEncodingEx(robj *o, int try_trim); robj *getDecodedObject(robj *o); size_t stringObjectLen(robj *o); robj *createStringObjectFromLongLong(long long value);