Created
June 25, 2013 19:00
-
-
Save tysonmote/5861341 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redis' | |
def long_running_command | |
t = Thread.new do | |
conn = Redis.new | |
conn.client.call(["DEBUG", "SLEEP", "1"]) | |
end | |
sleep 0.1 # let it connect before we return | |
t | |
end | |
conn = Redis.new( timeout: 0.01 ) | |
p conn.client.call(["SET", "a", "A"]) | |
p conn.client.call(["SET", "b", "B"]) | |
wait = long_running_command | |
# This will time out | |
p conn.client.call(["GET", "b"]) rescue nil | |
wait.join | |
puts "done with long-running command" | |
# This prints "A" | |
p conn.client.call(["GET", "a"]) rescue nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment