Last active
December 27, 2015 13:09
-
-
Save tsabat/7330539 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
course = Course.find('biology') | |
#get post ids, stored as set | |
post_key_arr = Course.fetch('post_ids', course_id) | |
#warm cache | |
if post_arr | |
post_key_arr.each do |p| | |
post_arr << Post.fetch('id', p.id) | |
end | |
else | |
#cold cache | |
posts = Post.find_by_course_id(course_id).group(&:post_id) | |
post_key_arr = posts.keys | |
post_arr = posts.values | |
Redis.store_set('post-by-course-' + course_id, post_arr) | |
post_arr.each do |p| | |
Redis.add('post-' + p.id) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment