Skip to content

Instantly share code, notes, and snippets.

@whatupdave
Created August 23, 2011 22:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatupdave/1166763 to your computer and use it in GitHub Desktop.
Save whatupdave/1166763 to your computer and use it in GitHub Desktop.
emhiredis example
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