How to follow a user using tweetsharp?

How do I best implement Redis for caching of a user feed?

  • I've got a dashboard where i show tracks people have posted. Connected to this tracks_posted table are tables tracks, artists, tags, user (poster), some statistics, slugs for cute names etc etc. And it gathers this information for all the tracks posted by people you follow. How would i best implement redis? I intend to use its LRU feature, using it instead of memcached. Saving the id's of the tracks_posted for each user and then storing each track posted with all its information separately. It would mean a lot of hits to redis, though. 11 hits for the standard feed of 10 items. Save the complete model for the 10 last tracks posted for each user feed? A lot of redundancy in that, of course, since the same track posted can be in several feeds. Tracks posted can also be updated at any time, or rather, they will be updated often, because they also contain comments. These could of course be queried separately. This would make any edit of a track posted have to be updated in hundreds of places, if not more.

  • Answer:

    Save the IDs of the tracks for each user. That won't result in 11 hits, you can do it in two (with M-commands or pipelining) or even one with Redis Scripting.

Pierre Chapuis at Quora Visit the source

Was this solution helpful to you?

Other answers

I would definitely chose the first option. Invaliding cache in hundreds of places and maintaining data integrity with permanent data storage seem like a nightmare to me. You can store N track IDs in a Set for each user. You can even control the size of the Set, for example, only cache the freshest 100 IDs. Then store the complete model in individual Hashes. To avoid N+1 problem, you can use pipelining to get all matching Hashes in one around-trip. If you are using redis-rb or redis-py, this will be very simple.

Jeff Shi

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.