Class: QRubyDriver::QConnection
- Inherits:
-
Object
- Object
- QRubyDriver::QConnection
- Defined in:
- lib/q-ruby-driver/q_connection.rb
Constant Summary collapse
- @@BUFFER_SIZE =
2048
Instance Method Summary collapse
-
#close ⇒ Object
Closes the connection.
-
#get(obj) ⇒ Object
(also: #execute)
Sync Send.
-
#initialize(host = "localhost", port = 3000, username = ENV['USER']) ⇒ QConnection
constructor
Initializes the connection.
-
#send_raw(raw_message, sync = true) ⇒ Object
Takes a hex encoded representation of the message to send.
-
#set(obj) ⇒ Object
ASync send.
-
#table_info(table_name) ⇒ Object
Dumps table schema.
Constructor Details
#initialize(host = "localhost", port = 3000, username = ENV['USER']) ⇒ QConnection
Initializes the connection
9 10 11 12 13 |
# File 'lib/q-ruby-driver/q_connection.rb', line 9 def initialize(host="localhost", port=3000, username = ENV['USER']) @client_socket = TCPSocket.new(host, port) @client_socket.write [username, "001"].pack("a*H") @client_socket.recv(4).unpack("H*") end |
Instance Method Details
#close ⇒ Object
Closes the connection
45 46 47 |
# File 'lib/q-ruby-driver/q_connection.rb', line 45 def close @client_socket.close end |
#get(obj) ⇒ Object Also known as: execute
Sync Send
16 17 18 19 |
# File 'lib/q-ruby-driver/q_connection.rb', line 16 def get(obj) write_to_socket(obj, true) read_from_socket() end |
#send_raw(raw_message, sync = true) ⇒ Object
Takes a hex encoded representation of the message to send
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/q-ruby-driver/q_connection.rb', line 28 def send_raw(, sync=true) = [].pack("H*") @client_socket.write if ([1] == 1) read_from_socket() else nil end end |
#set(obj) ⇒ Object
ASync send
23 24 25 |
# File 'lib/q-ruby-driver/q_connection.rb', line 23 def set(obj) write_to_socket(obj, false) end |
#table_info(table_name) ⇒ Object
Dumps table schema
40 41 42 |
# File 'lib/q-ruby-driver/q_connection.rb', line 40 def table_info(table_name) get("meta #{table_name}") end |