Skip to content

Instantly share code, notes, and snippets.

@seivan
Created February 12, 2011 10:11
Show Gist options
  • Save seivan/823665 to your computer and use it in GitHub Desktop.
Save seivan/823665 to your computer and use it in GitHub Desktop.
def self.create_single_girlfriend_for_user(user_id, girlfriend_id, friend_hash)
if friend_hash['gender'] == 'female'
R.hset "user:#{user_id}:girlfriends", girlfriend_id, friend_hash['relationship_status']
if friend_hash['relationship_status'] == "Single"
return Friend.build_for_user_id(user_id, girlfriend_id, friend_hash)
end
end
end
-----
girlfriends.each do |gf_id, gf_hash|
old_relationship_status = R.hget("user:#{user.id}:girlfriends", gf_id)
if gf_hash['relationship_status'] == "Single" && old_relationship_status != "Single"
single_girlfriends << Friend.build_for_user_id(user.id, gf_id, gf_hash)
end
end
------
#Remove old cache and make a new one
R.del("user:#{user.id}:girlfriends")
R.mapped_hmset("user:#{user.id}:girlfriends", girlfriends_cache.to_a.flatten)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment