On Sat, Oct 6, 2012 at 10:12 AM, Endroits <
endr...@gmail.com> wrote:
> For school I'm building a simple Instagram like project and thought it would
> be great to try redis out for the speed. I've done a little research on
> Instagram and how they use Redis to power their main feed. I've been
> researching about Redis and looking at use cases for the past week and I
> think I've started to grasp what I'll do for the database structure.
>
> I have two question about the redis twitter clone example
> (
http://redis.io/topics/twitter-clone) under the updates section.
>
> 1. When someone creates a post their post_id goes into their personal
> posts_list. Then the program uses a for loop to put that post_id into every
> followers posts_list. Is this the most efficient way to do this? Efficient
> meaning storage space and speed?
There are two ways to do "feeds" (as they are generally known).
Fan-out, and fan-in. With fan-out, you write an entry for every
follower of person X when person X posts. With fan-in, when user Y
looks at their feed, you fetch posts from all of the people that Y
follows.
Fan-out is best when you have people viewing significantly more often
than posting. Fan-in is best when viewing is rare, space is at a
premium, or when you have a lot of extra processor (or can use
distributed processing to minimize latency).
That said, if you change post_list into a ZSET, then you can use
ZUNIONSTORE to combine post zsets for a fan-in operation, which
shouldn't be bad for academic purposes for quite a while.
> 2. The update section uses "SET post:10343 "$owner_id|$time|I'm having fun
> with Retwis"" to set the post. Can redis set the $owner_id and |$time|? Or
> where do they pull these variables from?
In the client.
- Josiah