Re: First Redis Project

48 views
Skip to first unread message

Josiah Carlson

unread,
Oct 6, 2012, 2:07:37 PM10/6/12
to redi...@googlegroups.com
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

Marty Weiner

unread,
Oct 6, 2012, 3:23:11 PM10/6/12
to redi...@googlegroups.com, redi...@googlegroups.com
That's a good way to do it. 

We do something similar.  When somebody posts, we go to each follower and push an id+timestamp in a background task.  We store a timestamp in case you follow somebody and we have to merge ids in time order (our ids are not orderable by themselves).

On 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?

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?

Thank you


--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/ucspABo5Qq0J.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

Endroits

unread,
Oct 6, 2012, 7:34:07 PM10/6/12
to redi...@googlegroups.com
Thanks for help.  Fanning out seems like a good idea for this case.

Another basic question I was wondering as well as I'm researching into this.  I will have comments and likes in this project.  Concerning the comments is it common practice to store the comment text in a SQL database and use Redis as an index?



Marty Weiner

unread,
Oct 6, 2012, 10:36:49 PM10/6/12
to redi...@googlegroups.com, redi...@googlegroups.com
We keep comments, likes, and all mappings in MySQL and cached in Redis or Memcache.  


On Oct 6, 2012, at 4:34 PM, Endroits <endr...@gmail.com> wrote:

Thanks for help.  Fanning out seems like a good idea for this case.

Another basic question I was wondering as well as I'm researching into this.  I will have comments and likes in this project.  Concerning the comments is it common practice to store the comment text in a SQL database and use Redis as an index?



--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/bbhqfPlfPpkJ.
Reply all
Reply to author
Forward
0 new messages