Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move untested EventMachine connection class to example

commit 60eeb9cd991d05df2497705745b549f4eedcd674 1 parent 2a70c11
@pietern pietern authored
View
47 examples/em.rb
@@ -6,8 +6,51 @@
#
# ruby -rubygems -Ilib examples/em.rb [pub|sub]
#
-require 'eventmachine'
-require 'hiredis/em'
+require "eventmachine"
+require "hiredis/reader"
+
+module Hiredis
+
+ module EM
+
+ class Connection < ::EM::Connection
+
+ CRLF = "\r\n".freeze
+
+ def initialize
+ super
+ @reader = Reader.new
+ @callbacks = []
+ end
+
+ def receive_data(data)
+ @reader.feed(data)
+ until (reply = @reader.gets) == false
+ receive_reply(reply)
+ end
+ end
+
+ def receive_reply(reply)
+ callback = @callbacks.shift
+ callback.call(reply) if callback
+ end
+
+ def send_command(*args)
+ args = args.flatten
+ send_data("*" + args.size.to_s + CRLF)
+ args.each do |arg|
+ arg = arg.to_s
+ send_data("$" + arg.size.to_s + CRLF + arg + CRLF)
+ end
+ end
+
+ def method_missing(sym, *args, &callback)
+ send_command(sym, *args)
+ @callbacks.push callback
+ end
+ end
+ end
+end
$cnt = 0
View
1  lib/hiredis/em.rb
@@ -1 +0,0 @@
-require 'hiredis/em/connection'
View
36 lib/hiredis/em/base.rb
@@ -1,36 +0,0 @@
-require 'hiredis/reader'
-
-module Hiredis
-
- module EM
-
- class Base < ::EM::Connection
-
- CRLF = "\r\n".freeze
-
- def initialize
- super
- @reader = Reader.new
- end
-
- def receive_data(data)
- @reader.feed(data)
- until (reply = @reader.gets) == false
- receive_reply(reply)
- end
- end
-
- def receive_reply(reply)
- end
-
- def send_command(*args)
- args = args.flatten
- send_data("*" + args.size.to_s + CRLF)
- args.each do |arg|
- arg = arg.to_s
- send_data("$" + arg.size.to_s + CRLF + arg + CRLF)
- end
- end
- end
- end
-end
View
25 lib/hiredis/em/connection.rb
@@ -1,25 +0,0 @@
-require 'hiredis/em/base'
-
-module Hiredis
-
- module EM
-
- class Connection < Base
-
- def initialize
- super
- @callbacks = []
- end
-
- def receive_reply(reply)
- callback = @callbacks.shift
- callback.call(reply) if callback
- end
-
- def method_missing(sym, *args, &callback)
- send_command(sym, *args)
- @callbacks.push callback
- end
- end
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.