Sha256: 33319d2ab1eac2f76c8a11089b00a64638a011d38ae6fe4eb5da5b92f6e296c5

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

module HAJ

  module Pool
    # Class to provide a POC for better pooling.
    class Generic

      DEFAULT_HOST     = 'localhost'.freeze
      DEFAULT_PORT     = 6379
      DEFAULT_TIMEOUT  = 2000
      DEFAULT_DATABASE = 0

      def initialize(opts = {})
        config = HAJ::Pool::Config.new(opts)

        host     = opts.fetch(:host) { DEFAULT_HOST }
        port     = opts.fetch(:port) { DEFAULT_PORT }
        timeout  = opts.fetch(:timeout) { DEFAULT_TIMEOUT }
        password = opts.fetch(:password) { nil }
        database = opts.fetch(:database) { DEFAULT_DATABASE }
        name     = opts.fetch(:name) { nil }

        @inner_pool = HAJ::Jedis::Pool.new(
          config,
          host,
          port,
          timeout,
          password,
          database,
          name
        )
      end

      def hold
        connection = @inner_pool.resource

        yield connection
      ensure
        connection.close if connection
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
haj-0.0.2 lib/haj/pool/generic.rb