class Redis::Rack::Connection

Constants

POOL_KEYS

Public Class Methods

new(options = {}) click to toggle source
# File lib/redis/rack/connection.rb, line 6
def initialize(options = {})
  @options = options
  @store = options[:redis_store]
  @pool = options[:pool]

  if @pool && !@pool.is_a?(ConnectionPool)
    raise ArgumentError, "pool must be an instance of ConnectionPool"
  end

  if @store && !@store.is_a?(Redis::Store)
    raise ArgumentError, "redis_store must be an instance of Redis::Store (currently #{@store.class.name})"
  end
end

Public Instance Methods

pool() click to toggle source
# File lib/redis/rack/connection.rb, line 34
def pool
  @pool ||= ConnectionPool.new(pool_options) { store } if pooled?
end
pool_options() click to toggle source
# File lib/redis/rack/connection.rb, line 42
def pool_options
  {
    size: @options[:pool_size],
    timeout: @options[:pool_timeout]
  }.reject { |key, value| value.nil? }.to_h
end
pooled?() click to toggle source
# File lib/redis/rack/connection.rb, line 28
def pooled?
  return @pooled if defined?(@pooled)

  @pooled = POOL_KEYS.any? { |key| @options.key?(key) }
end
store() click to toggle source
# File lib/redis/rack/connection.rb, line 38
def store
  @store ||= Redis::Store::Factory.create(@options[:redis_server], ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE })
end
with(&block) click to toggle source
# File lib/redis/rack/connection.rb, line 20
def with(&block)
  if pooled?
    pool.with(&block)
  else
    block.call(store)
  end
end