Sha256: 54468997a35f653dd5c1357a526e7f2d01deab9676f0002df3e62ee9a17ec525

Contents?: true

Size: 719 Bytes

Versions: 1

Compression:

Stored size: 719 Bytes

Contents

require "redis"

module Linger::Connections
  mattr_accessor :connections, default: {}
  mattr_accessor :configurator
  mattr_accessor :connector, default: ->(config) { Redis.new(config) }

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linger-0.1.0 lib/linger/connections.rb