Sha256: b0a3af2446a0eb372e098e5025e3e9cc886d620e527ed96644f0ef22c31b8746

Contents?: true

Size: 838 Bytes

Versions: 15

Compression:

Stored size: 838 Bytes

Contents

#!/usr/bin/env ruby

require 'eventmachine'
# the redis/synchrony gems need to be required in this particular order, see
# the redis-rb README for details
require 'hiredis'
require 'em-synchrony'
require 'redis/connection/synchrony'
require 'redis'

require 'em-synchrony/connection_pool'

module Flapjack
  class RedisPool < EventMachine::Synchrony::ConnectionPool

    def initialize(opts = {})
      config = opts.delete(:config)
      super(:size => opts[:size] || 5) {
        ::Redis.new(config)
      }
    end

    def empty!
      f = Fiber.current

      until @available.empty? && @pending.empty?
        begin
          conn = acquire(f)
          conn.quit
          @available.delete(conn)
        ensure
          if pending = @pending.shift
            pending.resume
          end
        end
      end
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
flapjack-0.6.53 lib/flapjack/redis_pool.rb
flapjack-0.6.52 lib/flapjack/redis_pool.rb
flapjack-0.6.51 lib/flapjack/redis_pool.rb
flapjack-0.6.50 lib/flapjack/redis_pool.rb
flapjack-0.6.49 lib/flapjack/redis_pool.rb
flapjack-0.6.48 lib/flapjack/redis_pool.rb
flapjack-0.6.47 lib/flapjack/redis_pool.rb
flapjack-0.6.46 lib/flapjack/redis_pool.rb
flapjack-0.6.45 lib/flapjack/redis_pool.rb
flapjack-0.6.44 lib/flapjack/redis_pool.rb
flapjack-0.6.43 lib/flapjack/redis_pool.rb
flapjack-0.6.42 lib/flapjack/redis_pool.rb
flapjack-0.6.41 lib/flapjack/redis_pool.rb
flapjack-0.6.40 lib/flapjack/redis_pool.rb
flapjack-0.6.39 lib/flapjack/redis_pool.rb