Class: Vines::Cluster::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/vines/cluster/connection.rb

Overview

Create and cache a redis database connection.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



9
10
11
# File 'lib/vines/cluster/connection.rb', line 9

def initialize
  @redis, @host, @port, @database, @password = nil, nil, nil, nil, nil
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



7
8
9
# File 'lib/vines/cluster/connection.rb', line 7

def database
  @database
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/vines/cluster/connection.rb', line 7

def host
  @host
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/vines/cluster/connection.rb', line 7

def password
  @password
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/vines/cluster/connection.rb', line 7

def port
  @port
end

Instance Method Details

#connectObject

Return a shared redis connection.



14
15
16
# File 'lib/vines/cluster/connection.rb', line 14

def connect
  @redis ||= create
end

#createObject

Return a new redis connection.



19
20
21
22
23
# File 'lib/vines/cluster/connection.rb', line 19

def create
  conn = EM::Hiredis::Client.new(@host, @port, @password, @database)
  conn.connect
  conn
end