On the page to do periodically send status "object viewing". Fold in Redis as HashSet with the structure:
name hash = object id
key = user id
value = timestamp
Choose the timeout for example for 5 seconds and consider all entries older than 5 seconds is invalid.
To build meter take the number of valid elements in the hash for a particular object.
To hash growing need to remove expired elements because Redis is not able to invalidinput elements HashSet. This can be done periodically or you can write a lua script which will do the insert of a new element and simultaneously remove expired.
ambrose answered on April 4th 20 at 13:02
It was a marketing ploy. You can do a random counter. If only the user has realized that he has competitors and quickly bought the right product.
Frederik_Friesen answered on April 4th 20 at 13:04
If you solve the problem technically, you first need to define the refresh rate or accuracy. That means the user is now watching this page? Active browser tab? But if he looked away? )) And do you really want to have such high precision, what business problem does it solve?
Vskidku there are 3 ways:
1) "old-fashioned": to build the nginx logs so that they are easy to parse and to take the number of requests for the desired page in the scan interval
2) to gather statistics on the level of the router application in redis (as recently proposed above)
3) the most accurate, but too expensive, this websocket to open the page and read where they came from.
terrence_Durgan answered on April 4th 20 at 13:06
Using the SignalR library, the number of active users stored in Redis Server