Created
August 23, 2011 22:20
-
-
Save whatupdave/1166763 to your computer and use it in GitHub Desktop.
emhiredis example
This file contains 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 'em-hiredis' | |
module EMServer | |
def post_init | |
puts "-- someone connected to the echo server!" | |
end | |
def receive_data data | |
redis = EM::Hiredis.connect | |
redis.callback do | |
op = redis.get key | |
op.callback do |value| | |
send_data value | |
close_connection_after_writing | |
end | |
end | |
end | |
def unbind | |
puts "-- someone disconnected" | |
end | |
end | |
EM.run { | |
EM.start_server "127.0.0.1", 8081, EMServer | |
puts 'running echo server on 8081' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment