yojimbo87
yojimbo87

Reputation: 68305

Storing object properties in redis

Lets say I have an object (User) which consists of a few properties (ID, Name, Surename, Age). Which way is better to store this object in redis?

Upvotes: 27

Views: 13962

Answers (3)

Erik Bergstedt
Erik Bergstedt

Reputation: 912

From my tests using hash takes much smaller space, but that is about the only reason. If you have a lot of data consider using hash. Otherwise you might as well use JSON since it's easy to serialize and deserialize it to objects if you so wish, and handle in general.

Upvotes: 0

Aurel
Aurel

Reputation: 3740

From official Redis

Use hashes when possible

Small hashes are encoded in a very small space

When you haven't to much fields in it.

Every time an hash will exceed the number of elements or element size specified it will be converted into a real hash table, and the memory saving will be lost.

Upvotes: 1

yojimbo87
yojimbo87

Reputation: 68305

According to these two sources probably the optimal solution would be to use hashes because of memory consumption when using dedicated keys and long string in scenario with JSON as key value.

Upvotes: 21

Related Questions