public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
class Slug
class << self
def [](slug)
redis.hget(hash, slug)
end
def []=(slug, id)
if old = self[slug]
redis.srem(set(old), slug)
end
redis.hset(hash, slug, id)
redis.sadd(set(id), slug)
end
private
def redis
$redis
end
 
def hash
"post_ids"
end
 
def set(id)
"post_slugs_#{id}"
end
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.