When we doing something like set name Jack in Redis, because the length of string "Jack" is less than 39Bytes(<3.2) or 44 Bytes(>=3.2), string "Jack" will be stored using the "embstr" encoding, sds object will be stored in the same memory block right after RedisObject.

This is the redisObject struct

typedef struct redisObject {
    unsigned type:4;
    unsigned encoding:4;
    unsigned lru:LRU_BITS; /* LRU time (relative to global lru_clock) or
                            * LFU data (least significant 8 bits frequency
                            * and most significant 16 bits access time). */
    int refcount;
    void *ptr;
} robj;

My question: is the pointer(*ptr) of the RedisObject that often use to point to sds obejct being used when using embstr encoding? because in this situation, the sds object stores right after the RedisObject, it seems that we don't need to use the pointer to find where the sds object is(I guess).

Comment From: oranagra

The pointer is used by all readers, who usually treat this object as a normal string, and don't have any special handling for embedded strings. The purpose of this encoding type was to reduce heap allocations, not memory. It probably also improve cache locality, and removing the excess pointer would further help here, but will require a lot of code to handle these in all the reading flows. Note that it'll always save memory, since the allocator bins have fixed sizes.