N
N
NioTrest2017-04-04 09:46:08
Redis
NioTrest, 2017-04-04 09:46:08

Is it possible to store such data in Redis?

In a laravel application, I want to show the user information about who is currently viewing a particular page.
In Redis, I'm going to save information in this format:
{'/item/35': {1: last_visit_time_in_seconds}}
If two more users visit the /item/35 page, then Redis will have

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

Users with id 1, 12 and 2425 are on this page. If there is no update for user one {1: seconds}within 30 seconds, then information about him should be removed from the cache, but the record about other users should remain. The frontend periodically sends requests to the backend to maintain the state of the cache.
Is it possible to do this in Redis? Maybe there is another way to store this kind of information in the cache?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leonid, 2017-04-04
@NioTrest

You can do this:
When the user opens the page, create an entry in redis with the TTL you need using SETEX.
The key is something like this: opened:item_35:user_id. The value doesn't matter.
To find out the users on this page, make the request keys opened:item_35:* and parse the user_id from the received keys.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question