I’m setting up a redis store where my session user_id values are stored in the cookie and the rest of the model data (first_name, last_name, username, etc…) are stored in redis. I’m very new to Redis and I’m not sure how to store the model data.
I have two questions:
-
What’s the best way to store it, should I serialize it in XML, JSON or a ruby object equivalent.
-
When the stored data is fetched, how can I transform that into a working model object? That way when I do user_fetched_from_redis.username then it would work like user_fetched_from_db.username. And if there are any fields that are not fetched from the redis store then I would want activerecord to do a SELECT * FROM statement to populate all the attributes in the object. Is this possible?
The solution to this problem can be found here in another post.
Existing Rails model without fetching it from the database