Sunday, 25 August 2013

can't understand how redis works with rails

can't understand how redis works with rails

I'm new on redis and i find that learning redis basics is very easy, but
when i try to understand how i can use it with rails, it become flow and i
can't find any good tutoriel which explains steps from scratch , for
example i find code like this :
class User < ActiveRecord::Base
# follow a user
def follow!(user)
$redis.multi do
$redis.sadd(self.redis_key(:following), user.id)
$redis.sadd(user.redis_key(:followers), self.id)
end
end
# unfollow a user
def unfollow!(user)
$redis.multi do
$redis.srem(self.redis_key(:following), user.id)
$redis.srem(user.redis_key(:followers), self.id)
end
end
but with this example, no other example show how to use follow method,
what is the object i need pass to this method (is this object from a
relational database ? or what ) etc ...
all examples i find in my search are incomplete, and this rend redis not
easy at all when we decide to use it with rails !
I also find that the use of redis is at the model that inherits from
ActiveRecord, I can not understand: if redis is used in the majority of
cases with a relational database or alone, and what is the way most used,
and how exactly ?
i know that my question is vast but what i search is how use redis and
rails together, also if you have a good resource for me, i will very
appreciate that. thank you

No comments:

Post a Comment