Monday, April 3, 2017

Can I store in Redis this type of data?

I'm writing laravel application, where I want to show current user all other users on the page.

I want to use Redis to store this kind of information, so, for example, when user 1 visits page /item/35, then Redis must save this info:

{'/item/35': {1: last_visit_time_in_seconds}}

Where last_visit_time_in_seconds is unixtimestamp.

If two additional users visit same page, then Redis would contain:

{'/item/35': {1: seconds}, {12: seconds}, {2425: seconds}}

Users with ids 1, 12 and 2425 are viewing this page right now. If there are no updates for {1: seconds} for a short period of time (like 30 seconds), then this item must be removed from this item cache. Frontend periodically updates state of cache, so this is safeguard against user closing browser window.

May be there is a better way in Redis to store/get this kind of info (map from item to the list of users with their last visit time).



via Jackson J

Advertisement