travis-api/lib/travis/redis_pool.rb
Aakriti Gupta 65f1a29d86 Move travis-core files from /vendor to /lib.
- Re-factor
- Remove code for notifications
- Remove addons
- Remove travis-core gem.
- Ignore logs directory only
- Move core tests to spec/lib
2016-07-20 11:22:25 +02:00

33 lines
722 B
Ruby

require 'connection_pool'
require 'redis'
require 'metriks'
module Travis
class RedisPool
attr_reader :pool
def initialize(options = {})
pool_options = options.delete(:pool) || {}
pool_options[:size] ||= 10
pool_options[:timeout] ||= 10
@pool = ConnectionPool.new(pool_options) do
::Redis.new(options)
end
end
def method_missing(name, *args, &block)
timer = Metriks.timer('redis.pool.wait').time
@pool.with do |redis|
timer.stop
if redis.respond_to?(name)
Metriks.timer("redis.operations").time do
redis.send(name, *args, &block)
end
else
super
end
end
end
end
end