Reputation: 357
I want to use redis to store the count of profile views by different users. Instead of updating the table on every page view(increasing the count with 1) I am thinking of storing and increasing the count(of views) for that profile in a list or something on redis.Then at regular intervals pop the collective count from the list and update the table. So the number of queries to the DB could be reduced. Would lists be a better to use or any other data structure.Could there be any other better way to do so?
Upvotes: 0
Views: 430
Reputation: 50052
A List is less suitable in this case, if only because its members are immutable and you're looking to update counts.
Instead, consider using a Hash in which each field is represents a profile and the value is the counter for that page.
Each page view triggers an HINCRBY
to the relevant field's value. Periodically you can read that Hash's contents, delete it and add the deltas to your database.
Upvotes: 1