Sha256: 7eabe6ea5ee8555fd24ac363ce4fc322e29ce6b442dc7773ef4d997425104bdf

Contents?: true

Size: 1019 Bytes

Versions: 4

Compression:

Stored size: 1019 Bytes

Contents

require 'redis'
require 'connection_pool'
require 'active_model'
require 'active_support/all'
require 'yaml'
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_accessor :connection_pool, :redis_options, :connection_pool_size,
                  :connection_pool_timeout
  end

  self.redis_options = { driver: :hiredis }
  self.connection_pool_size = 5
  self.connection_pool_timeout = 5

  def self.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 self.with_connection
    connection_pool.with { |connection| yield(connection) }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
modis-1.4.2 lib/modis.rb
modis-1.4.1-java lib/modis.rb
modis-1.4.1 lib/modis.rb
modis-1.4.0 lib/modis.rb