RienNeVaPlu͢s
RienNeVaPlu͢s

Reputation: 7632

Redis hash: Key name compression

When working with Redis hashes I often end up storing 99% of identical keys:

HGETALL object:someID {
    "id": "123",
    "someSpecificKeysWithLongNames": "..."
}

How does Redis store the hash? Is it able to reduce the allocated space required for keynames, or should I rather use short keys to reduce the overhead?

HGETALL myobject {
    "i": "123",
    "s": "..."
}

Upvotes: 2

Views: 1786

Answers (1)

Sripathi Krishnan
Sripathi Krishnan

Reputation: 31528

Redis does not compress key names in any version, regardless of the underlying data structure. If your keys are identical, you will benefit from using shorter keys.

I would suggest doing some empirical calculations to find out the savings before you actually refactor. Based on your example, you'd at least save len(someSpecificKeysWithLongNames) - len(s) bytes per hash. Multiply that by the number of hashes you have or plan to have, and then do a cost-benefit to see if the savings are worth the pain.

Upvotes: 3

Related Questions