Skip to content

Instantly share code, notes, and snippets.

@tysonmote
Created June 25, 2013 19:00
Show Gist options
  • Save tysonmote/5861341 to your computer and use it in GitHub Desktop.
Save tysonmote/5861341 to your computer and use it in GitHub Desktop.
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