Class: EventMachine::Protocols::Memcache::Server
- Inherits:
-
Object
- Object
- EventMachine::Protocols::Memcache::Server
- Defined in:
- lib/evented_memcache_client/server.rb
Constant Summary collapse
- DEFAULT_PORT =
22122
- DEFAULT_HOST =
'localhost'
Instance Attribute Summary collapse
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #close(conn) ⇒ Object
- #get(conn, data, args) ⇒ Object
-
#initialize(host = nil, port = nil) ⇒ Server
constructor
Create a new memcache server listener, on the specified host and port.
-
#open(conn) ⇒ Object
Callbacks from the connection.
- #set(conn, data, args) ⇒ Object (also: #replace, #prepend, #append, #add)
-
#start ⇒ Object
Start listening for client connections.
-
#stop ⇒ Object
Stop listening for client connections, and close any open clients.
Constructor Details
#initialize(host = nil, port = nil) ⇒ Server
Create a new memcache server listener, on the specified host and port.
40 41 42 43 44 |
# File 'lib/evented_memcache_client/server.rb', line 40 def initialize(host=nil, port=nil) @host = host || DEFAULT_HOST @port = port || DEFAULT_PORT @connections = [] end |
Instance Attribute Details
#connections ⇒ Object
Returns the value of attribute connections.
34 35 36 |
# File 'lib/evented_memcache_client/server.rb', line 34 def connections @connections end |
#host ⇒ Object
Returns the value of attribute host.
35 36 37 |
# File 'lib/evented_memcache_client/server.rb', line 35 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
36 37 38 |
# File 'lib/evented_memcache_client/server.rb', line 36 def port @port end |
Instance Method Details
#close(conn) ⇒ Object
86 87 88 |
# File 'lib/evented_memcache_client/server.rb', line 86 def close(conn) @connections.delete(conn) end |
#get(conn, data, args) ⇒ Object
98 99 100 |
# File 'lib/evented_memcache_client/server.rb', line 98 def get(conn, data, args) # we don't do nuffing end |
#open(conn) ⇒ Object
Callbacks from the connection
82 83 84 |
# File 'lib/evented_memcache_client/server.rb', line 82 def open(conn) @connections << conn end |
#set(conn, data, args) ⇒ Object Also known as: replace, prepend, append, add
90 91 92 |
# File 'lib/evented_memcache_client/server.rb', line 90 def set(conn, data, args) # we don't do nuffing end |
#start ⇒ Object
Start listening for client connections.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/evented_memcache_client/server.rb', line 47 def start begin @signature = EventMachine.start_server(@host, @port.to_i, Connectable, self) { |conn| conn.set_handler(self) # Usually called from EM; we fake it out. conn.connection_completed } rescue => e return false else return true end end |
#stop ⇒ Object
Stop listening for client connections, and close any open clients.
67 68 69 70 71 72 73 74 75 |
# File 'lib/evented_memcache_client/server.rb', line 67 def stop EventMachine.stop_server(@signature) unless wait_for_connections # Still some running EventMachine.add_periodic_timer(1) { wait_for_connections } end end |