Redis Usecase: Activity Stream Caching
Excellent Redis use case from PeachShake:
My solution was to leave the data storage in MySQL, but move the stream construction into Redis. Instead of querying MySQL and doing the joins to make the stream, I just create a linear stream for each user and append new IDs to it every time an action occurs. Then, the MySQL query is a dead-simple “SELECT WHERE IN” query using the IDs pulled from the Redis list. This takes a 30+ second MySQL query down to a few milliseconds.
As always, the main issue is synchronization. I have to make sure that the Redis activity stream matches the activities stored in MySQL.
Couple of comments though:
- I’d try my best to avoid
SELECT WHERE IN(depending on the size of the data I’d try to assemble it and place it directly in Redis. In other words, cache at a higher level) - Activity streams do not require perfect synchronization
Added to the Powered by Redis.
Original title and link: Redis Usecase: Activity Stream Caching (NoSQL databases © myNoSQL)
via: http://peachshake.com/2010/10/04/initial-thoughts-on-redis/