Skip to content

Instantly share code, notes, and snippets.

@npj
Created May 4, 2012 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save npj/2596220 to your computer and use it in GitHub Desktop.
Save npj/2596220 to your computer and use it in GitHub Desktop.
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
def destroy(id)
redis.smembers(set(id)).each { |slug| redis.hdel(hash, slug) }
redis.del(set(id))
end
private
def redis
$redis
end
def hash
"post_ids"
end
def set(id)
"post_slugs_#{id}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment