Class: Oxblood::Connection
- Inherits:
-
Object
- Object
- Oxblood::Connection
- Defined in:
- lib/oxblood/connection.rb
Overview
Class responsible for connection maintenance
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
-
#transaction_mode ⇒ Boolean
Transaction status.
Instance Method Summary collapse
-
#in_transaction? ⇒ Boolean?
private
Connection transaction status.
-
#initialize(opts = {}) ⇒ Connection
constructor
Initialize connection to Redis server.
-
#read_response ⇒ Object
Read response from server.
-
#run_command(*command) ⇒ Object
Send command to Redis server and read response from it.
-
#send_command(*command) ⇒ Integer
Send comand to Redis server.
Constructor Details
#initialize(opts = {}) ⇒ Connection
Initialize connection to Redis server
31 32 33 34 35 36 37 38 |
# File 'lib/oxblood/connection.rb', line 31 def initialize(opts = {}) @in_transaction = false @socket = RSocket.new(opts) session = Session.new(self) session.auth(opts[:password]) if opts[:password] session.select(opts[:db]) if opts[:db] end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
11 12 13 |
# File 'lib/oxblood/connection.rb', line 11 def socket @socket end |
#transaction_mode ⇒ Boolean
Returns transaction status.
16 17 18 |
# File 'lib/oxblood/connection.rb', line 16 def transaction_mode @transaction_mode end |
Instance Method Details
#in_transaction? ⇒ Boolean?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Connection transaction status.
73 74 75 |
# File 'lib/oxblood/connection.rb', line 73 def in_transaction? transaction_mode end |
#read_response ⇒ Object
Raise specific error if server has nothing to answer.
Will raise RSocket::TimeoutError even if there is simply no response to read from server. For example, if you are trying to read response before sending command.
Read response from server
65 66 67 |
# File 'lib/oxblood/connection.rb', line 65 def read_response Protocol.parse(@socket) end |
#run_command(*command) ⇒ Object
Send command to Redis server and read response from it
54 55 56 57 |
# File 'lib/oxblood/connection.rb', line 54 def run_command(*command) send_command(*command) read_response end |
#send_command(*command) ⇒ Integer
Send comand to Redis server
47 48 49 |
# File 'lib/oxblood/connection.rb', line 47 def send_command(*command) @socket.write(Protocol.build_command(*command)) end |