Skip to content

Instantly share code, notes, and snippets.

@akahn
Created January 10, 2012 15:11
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 akahn/e1ff97cd9e1138cc6d97 to your computer and use it in GitHub Desktop.
Save akahn/e1ff97cd9e1138cc6d97 to your computer and use it in GitHub Desktop.
def no_redis(redis)
redis.del "list"
# Block for up to 5 seconds
t = Thread.new { redis.blpop "list", 1 }
result = yield
# After yielding, stop blocking
redis.lpush "list", "foo"
t.join
result
end
r = Redis.new(:timout => 0.1)
no_redis(r) { r.ping } # => raises Errno::EAGAIN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment