Module: Redistat::Connection

Defined in:
lib/redistat/connection.rb

Constant Summary collapse

REQUIRED_SERVER_VERSION =
"1.3.10"
MIN_EXPIRE_SERVER_VERSION =
"2.1.3"

Class Method Summary collapse

Class Method Details

.add(conn, ref = nil) ⇒ Object



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

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



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

def connections
  @connections ||= {}
end

.create(options = {}) ⇒ Object



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

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



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

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

.referencesObject



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

def references
  @references ||= {}
end