Class: EventMachine::HandlerSocket::Client

Inherits:
Connection
  • Object
show all
Includes:
Deferrable, Protocols::LineProtocol
Defined in:
lib/em-handlersocket/client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



37
38
39
# File 'lib/em-handlersocket/client.rb', line 37

def initialize
  @deferrables = []
end

Instance Method Details

#connection_completedObject



41
42
43
# File 'lib/em-handlersocket/client.rb', line 41

def connection_completed
  succeed
end

#delete(q) ⇒ Object



57
58
59
# File 'lib/em-handlersocket/client.rb', line 57

def delete(q)
  execute([[q[:id], q[:op], q[:key].size, q[:key], (q[:limit] || 1), (q[:offset] || 0), 'D']])
end

#execute(cmd, &blk) ⇒ Object



65
66
67
68
# File 'lib/em-handlersocket/client.rb', line 65

def execute(cmd, &blk)
  callback { send(cmd) }
  add_deferrable(cmd.size, &blk)
end

#insert(opts) ⇒ Object



53
54
55
# File 'lib/em-handlersocket/client.rb', line 53

def insert(opts)
  execute([[opts[:id], '+', opts[:data].size, opts[:data]]])
end

#open_index(opts) ⇒ Object



45
46
47
# File 'lib/em-handlersocket/client.rb', line 45

def open_index(opts)
  execute([['P', opts[:id], opts[:db], opts[:table], opts[:index_name], opts[:columns]]])
end

#query(*qu) ⇒ Object



49
50
51
# File 'lib/em-handlersocket/client.rb', line 49

def query(*qu)
  execute(qu.map{|q| [q[:id], q[:op], q[:key].size, q[:key], q[:limit], q[:offset]].compact })
end

#update(q) ⇒ Object



61
62
63
# File 'lib/em-handlersocket/client.rb', line 61

def update(q)
  execute([[q[:id], q[:op], q[:key].size, q[:key], (q[:limit] || 1), (q[:offset] || 0), 'U', q[:data]]])
end