Sha256: f6ed883599cecbfcb60acea24fd1ea452e5367e0fd2df936cb2f28e86c39750d

Contents?: true

Size: 673 Bytes

Versions: 3

Compression:

Stored size: 673 Bytes

Contents

require "redis"

module Kredis::Connections
  mattr_accessor :connections, default: Hash.new
  mattr_accessor :configurator

  def configured_for(name)
    connections[name] ||= begin
      Kredis.instrument :meta, message: "Connected to #{name}" do
        Redis.new configurator.config_for("redis/#{name}")
      end
    end
  end

  def clear_all
    Kredis.instrument :meta, message: "Connections all cleared" do
      connections.each_value do |connection|
        if Kredis.namespace
          keys = connection.keys("#{Kredis.namespace}:*")
          connection.del keys if keys.any?
        else
          connection.flushdb
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kredis-0.4.0 lib/kredis/connections.rb
kredis-0.3.1 lib/kredis/connections.rb
kredis-0.3.0 lib/kredis/connections.rb