class Jylis::Connection
A connection to the database.
Public Class Methods
@param server_uri [URI, String] uri of the server to connect to
@raise [UnsupportedSchemaError] if the server URI schema is not supported @raise [HostMissingError] if the host is missing from the server URI
# 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
Public Instance Methods
@return [Boolean] true if a connection to the server is established
# File lib/jylis-rb/connection.rb, line 36 def connected? @connection.connected? end
Disconnect from the server.
# File lib/jylis-rb/connection.rb, line 48 def disconnect @connection.disconnect end
GCOUNT functions
@return [Jylis::DataType::GCOUNT]
# File lib/jylis-rb/connection.rb, line 87 def gcount @gcount ||= Jylis::DataType::GCOUNT.new(self) end
MVREG functions
@return [Jylis::DataType::MVREG]
# File lib/jylis-rb/connection.rb, line 101 def mvreg @mvreg ||= Jylis::DataType::MVREG.new(self) end
PNCOUNT functions
@return [Jylis::DataType::PNCOUNT]
# File lib/jylis-rb/connection.rb, line 94 def pncount @pncount ||= Jylis::DataType::PNCOUNT.new(self) end
Make a query to the database.
@param args data type function args. Can be an args list or array.
@return [Array] query response
@see jemc.github.io/jylis/docs/types/
# 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 to the server.
# File lib/jylis-rb/connection.rb, line 41 def reconnect disconnect if connected? connect end
TLOG functions
@return [Jylis::DataType::TLOG]
# File lib/jylis-rb/connection.rb, line 80 def tlog @tlog ||= Jylis::DataType::TLOG.new(self) end
TREG functions
@return [Jylis::DataType::TREG]
# File lib/jylis-rb/connection.rb, line 73 def treg @treg ||= Jylis::DataType::TREG.new(self) end
UJSON functions
@return [Jylis::DataType::UJSON]
# File lib/jylis-rb/connection.rb, line 108 def ujson @ujson ||= Jylis::DataType::UJSON.new(self) end
Private Instance Methods
Connect to the server.
# File lib/jylis-rb/connection.rb, line 115 def connect @connection.connect(@server_host, @server_port) end