Class: Xunch::FiberRedisPool
- Inherits:
-
Object
- Object
- Xunch::FiberRedisPool
- Defined in:
- lib/xunch/connection/fiber_redis_pool.rb
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(options) ⇒ FiberRedisPool
constructor
A new instance of FiberRedisPool.
-
#pool_status ⇒ Hash
Returns current pool utilization.
- #with ⇒ Object
Constructor Details
#initialize(options) ⇒ FiberRedisPool
Returns a new instance of FiberRedisPool.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/xunch/connection/fiber_redis_pool.rb', line 4 def initialize() @reserved = {} # map of in-progress connections @available = [] # pool of free connections @pending = [] # pending reservations (FIFO) @pool_timeout = [:pool_timeout] p [:size] [:size].times do @available.push(redis = Redis.new()) end @closed = false end |
Instance Method Details
#destroy ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/xunch/connection/fiber_redis_pool.rb', line 30 def destroy if !@closed @closed = true @available.each {|redis| redis.quit if redis and redis.connected?} @reserved.each {|redis| redis.quit if redis and redis.connected?} end end |
#pool_status ⇒ Hash
Returns current pool utilization.
41 42 43 44 45 46 47 48 |
# File 'lib/xunch/connection/fiber_redis_pool.rb', line 41 def pool_status { close: @closed, available: @available.size, reserved: @reserved.size, pending: @pending.size } end |
#with ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/xunch/connection/fiber_redis_pool.rb', line 20 def with f = Fiber.current begin conn = checkout_redis(f) yield conn ensure checkin_redis(f) end end |