Sha256: a5f02a2a38d63ca0f4421a8eaa03ffdbc5c2503294492c54cfa2332f8d933fda

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'redis'
require 'connection_pool'
require 'active_model'
require 'active_support/all'
require 'msgpack'

require 'modis/version'
require 'modis/configuration'
require 'modis/attribute'
require 'modis/errors'
require 'modis/persistence'
require 'modis/transaction'
require 'modis/finder'
require 'modis/index'
require 'modis/model'

module Modis
  @mutex = Mutex.new

  class << self
    attr_writer :redis_options, :connection_pool_size, :connection_pool_timeout,
                :connection_pool

    def redis_options
      @redis_options ||= { driver: :hiredis }
    end

    def connection_pool_size
      @connection_pool_size ||= 5
    end

    def connection_pool_timeout
      @connection_pool_timeout ||= 5
    end

    def connection_pool
      return @connection_pool if @connection_pool

      @mutex.synchronize do
        options = { size: connection_pool_size, timeout: connection_pool_timeout }
        @connection_pool = ConnectionPool.new(options) { Redis.new(redis_options) }
      end
    end

    def with_connection
      connection_pool.with { |connection| yield(connection) }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
modis-3.3.0 lib/modis.rb
modis-3.2.0 lib/modis.rb
modis-3.1.0 lib/modis.rb
modis-3.0.0 lib/modis.rb