Class: Jylis::Connection
- Inherits:
-
Object
- Object
- Jylis::Connection
- Defined in:
- lib/jylis-rb/connection.rb
Overview
A connection to the database.
Defined Under Namespace
Classes: HostMissingError, UnsupportedSchemaError
Data Types collapse
-
#gcount ⇒ Jylis::DataType::GCOUNT
GCOUNT functions.
-
#mvreg ⇒ Jylis::DataType::MVREG
MVREG functions.
-
#pncount ⇒ Jylis::DataType::PNCOUNT
PNCOUNT functions.
-
#tlog ⇒ Jylis::DataType::TLOG
TLOG functions.
-
#treg ⇒ Jylis::DataType::TREG
TREG functions.
-
#ujson ⇒ Jylis::DataType::UJSON
UJSON functions.
Instance Method Summary collapse
-
#connected? ⇒ Boolean
True if a connection to the server is established.
-
#disconnect ⇒ Object
Disconnect from the server.
-
#initialize(server_uri) ⇒ Connection
constructor
A new instance of Connection.
-
#query(*args) ⇒ Array
Make a query to the database.
-
#reconnect ⇒ Object
Reconnect to the server.
Constructor Details
#initialize(server_uri) ⇒ Connection
Returns a new instance of Connection.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jylis-rb/connection.rb', line 15 def initialize(server_uri) server_uri = URI.parse(server_uri) unless server_uri.is_a?(URI) unless server_uri.scheme.downcase == "jylis" raise UnsupportedSchemaError.new( "#{server_uri.scheme} is not a supported schema" ) end unless server_uri.host raise HostMissingError.new("No host specified") end @server_host = server_uri.host @server_port = server_uri.port || 6379 @connection = Hiredis::Connection.new connect end |
Instance Method Details
#connected? ⇒ Boolean
Returns true if a connection to the server is established.
36 37 38 |
# File 'lib/jylis-rb/connection.rb', line 36 def connected? @connection.connected? end |
#disconnect ⇒ Object
Disconnect from the server.
48 49 50 |
# File 'lib/jylis-rb/connection.rb', line 48 def disconnect @connection.disconnect end |
#gcount ⇒ Jylis::DataType::GCOUNT
GCOUNT functions
87 88 89 |
# File 'lib/jylis-rb/connection.rb', line 87 def gcount @gcount ||= Jylis::DataType::GCOUNT.new(self) end |
#mvreg ⇒ Jylis::DataType::MVREG
MVREG functions
101 102 103 |
# File 'lib/jylis-rb/connection.rb', line 101 def mvreg @mvreg ||= Jylis::DataType::MVREG.new(self) end |
#pncount ⇒ Jylis::DataType::PNCOUNT
PNCOUNT functions
94 95 96 |
# File 'lib/jylis-rb/connection.rb', line 94 def pncount @pncount ||= Jylis::DataType::PNCOUNT.new(self) end |
#query(*args) ⇒ Array
Make a query to the database.
59 60 61 62 63 64 65 66 |
# File 'lib/jylis-rb/connection.rb', line 59 def query(*args) if args.count == 1 && args.first.is_a?(Array) args = *args.first end @connection.write(args) @connection.read end |
#reconnect ⇒ Object
Reconnect to the server.
41 42 43 44 45 |
# File 'lib/jylis-rb/connection.rb', line 41 def reconnect disconnect if connected? connect end |
#tlog ⇒ Jylis::DataType::TLOG
TLOG functions
80 81 82 |
# File 'lib/jylis-rb/connection.rb', line 80 def tlog @tlog ||= Jylis::DataType::TLOG.new(self) end |
#treg ⇒ Jylis::DataType::TREG
TREG functions
73 74 75 |
# File 'lib/jylis-rb/connection.rb', line 73 def treg @treg ||= Jylis::DataType::TREG.new(self) end |
#ujson ⇒ Jylis::DataType::UJSON
UJSON functions
108 109 110 |
# File 'lib/jylis-rb/connection.rb', line 108 def ujson @ujson ||= Jylis::DataType::UJSON.new(self) end |