Class: Redis::Connection::Oxblood
- Inherits:
-
Object
- Object
- Redis::Connection::Oxblood
- Defined in:
- lib/redis/connection/oxblood.rb
Class Method Summary collapse
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #disconnect ⇒ Object
- #encode(string) ⇒ Object
-
#initialize(connection) ⇒ Oxblood
constructor
A new instance of Oxblood.
- #read ⇒ Object
- #timeout=(timeout) ⇒ Object
- #write(command) ⇒ Object
Constructor Details
#initialize(connection) ⇒ Oxblood
Returns a new instance of Oxblood.
18 19 20 |
# File 'lib/redis/connection/oxblood.rb', line 18 def initialize(connection) @connection = connection end |
Class Method Details
.connect(config) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/redis/connection/oxblood.rb', line 8 def self.connect(config) unless config[:path] config = config.dup config.delete(:path) end connection = ::Oxblood::Connection.new(config) new(connection) end |
Instance Method Details
#connected? ⇒ Boolean
22 23 24 |
# File 'lib/redis/connection/oxblood.rb', line 22 def connected? @connection.socket && @connection.socket.connected? end |
#disconnect ⇒ Object
30 31 32 |
# File 'lib/redis/connection/oxblood.rb', line 30 def disconnect @connection.socket.close end |
#encode(string) ⇒ Object
50 51 52 |
# File 'lib/redis/connection/oxblood.rb', line 50 def encode(string) string.force_encoding(Encoding::default_external) end |
#read ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/redis/connection/oxblood.rb', line 38 def read reply = @connection.read_response reply = encode(reply) if reply.is_a?(String) reply = CommandError.new(reply.) if reply.is_a?(::Oxblood::Protocol::RError) reply rescue ::Oxblood::Protocol::ParserError => e raise Redis::ProtocolError.new(e.) rescue ::Oxblood::RSocket::TimeoutError => e raise Redis::TimeoutError.new(e.) end |
#timeout=(timeout) ⇒ Object
26 27 28 |
# File 'lib/redis/connection/oxblood.rb', line 26 def timeout=(timeout) @connection.socket.timeout = timeout > 0 ? timeout : nil end |
#write(command) ⇒ Object
34 35 36 |
# File 'lib/redis/connection/oxblood.rb', line 34 def write(command) @connection.send_command(*command) end |