Class: Vines::Cluster::Connection
- Inherits:
-
Object
- Object
- Vines::Cluster::Connection
- Defined in:
- lib/vines/cluster/connection.rb
Overview
Create and cache a redis database connection.
Instance Attribute Summary collapse
-
#database ⇒ Object
Returns the value of attribute database.
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#connect ⇒ Object
Return a shared redis connection.
-
#create ⇒ Object
Return a new redis connection.
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize ⇒ Connection
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
#database ⇒ Object
Returns the value of attribute database.
7 8 9 |
# File 'lib/vines/cluster/connection.rb', line 7 def database @database end |
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/vines/cluster/connection.rb', line 7 def host @host end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/vines/cluster/connection.rb', line 7 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/vines/cluster/connection.rb', line 7 def port @port end |
Instance Method Details
#connect ⇒ Object
Return a shared redis connection.
14 15 16 |
# File 'lib/vines/cluster/connection.rb', line 14 def connect @redis ||= create end |
#create ⇒ Object
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 |