Module: Redistat::Connection

Defined in:
lib/redistat/connection.rb

Constant Summary collapse

REQUIRED_SERVER_VERSION =
"1.3.10"

Class Method Summary collapse

Class Method Details

.add(conn, ref = nil) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/redistat/connection.rb', line 21

def add(conn, ref = nil)
  ref ||= :default
  synchronize do
    check_redis_version(conn)
    references[ref] = conn.client.id
    connections[conn.client.id] = conn
  end
end

.connectionsObject



41
42
43
# File 'lib/redistat/connection.rb', line 41

def connections
  @connections ||= {}
end

.create(options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/redistat/connection.rb', line 30

def create(options = {})
  synchronize do
    options = options.clone
    ref = options.delete(:ref) || :default
    options.reverse_merge!(default_options)
    conn = (connections[connection_id(options)] ||= connection(options))
    references[ref] = conn.client.id
    conn
  end
end

.get(ref = nil) ⇒ Object

TODO: clean/remove all ref-less connections



14
15
16
17
18
19
# File 'lib/redistat/connection.rb', line 14

def get(ref = nil)
  ref ||= :default
  synchronize do
    connections[references[ref]] || create
  end
end

.referencesObject



45
46
47
# File 'lib/redistat/connection.rb', line 45

def references
  @references ||= {}
end