Skip to content

Instantly share code, notes, and snippets.

@tsabat
Last active December 27, 2015 13:09
Show Gist options
  • Save tsabat/7330539 to your computer and use it in GitHub Desktop.
Save tsabat/7330539 to your computer and use it in GitHub Desktop.
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