We are moving our session storage from on the app server to redis.
The session value is about 2k (it is huge I know, it will be shrunk drastically in the future).
We will have about 10 million session stored in there.
The question is should we store each one as key/value or save them all in one hash object? Is there benefit one over the other?
2
Answers
I don’t really get the "one hash object" part. With hashes, the thing is you can’t get the data back.
Just jsonify your session object, and store it as key / val, the key being the session_id stored in a cookie on the client.
From my point of view, the most difference between key/value and hash is using the TTL.
So you can use
TTL
on key/value. YOU CAN’T USETTL
WITHHASH
TYPE CHILDThe other thing to consider is the manual page which says the hashes type are good for representing the objects. but you can use them as well.
You can use hashes as each user session object and if you need to set
TTL
set it for the hash key.I don’t Think you need to select between these two types, you can combine them! expect of saving a json string to the key/value pair.
for example, this is how I set the user 123 session data which it will expire after 5 minutes (300 seconds):
You can change
SESSION:123
withSESSION:{session_id}