skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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 USE TTL WITH HASH TYPE CHILD

    The 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):

    redis> HSET SESSION:123 firstname "Ali" lastname "Malek" credentials "P@sSw0rd"
    1
    redis> EXPIRE SESSION:123 300
    1
    redis> HGET SESSION:123 username
    "Ali"
    

    You can change SESSION:123 with SESSION:{session_id}

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search