def replace(models)
      ids = models.map(&:id)

      model.synchronize do
        redis.queue("MULTI")
        redis.queue("DEL", key)
        ids.each { |id| redis.queue("SADD", key, id) }
        redis.queue("EXEC")
        redis.commit
      end
    end
def replace(models)
      ids = models.map(&:id)

      model.synchronize do
        redis.queue("MULTI")
        redis.queue("DEL", key)
        ids.each { |id| redis.queue("SADD", key, id) }
        redis.queue("EXEC")
        redis.commit
      end
    end
Replace all the existing elements of a set with a different
 collection of models. This happens atomically in a MULTI-EXEC
 block.

 Example:

   user = User.create
   p1 = Post.create
   user.posts.add(p1)

   p2, p3 = Post.create, Post.create
   user.posts.replace([p2, p3])

   user.posts.include?(p1)
   # => false