Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Models
- module Likable
- extend ActiveSupport::Concern
- def liked?(record)
- $redis.sismember redis_key, record.id
- end
- def likes_count
- $redis.scard redis_key
- end
- def like(record)
- $redis.sadd record.redis_key, id
- end
- protected
- def redis_key
- "likes:#{id}:#{self.class.model_name}"
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment