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 |
# 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] [:size].times do @available.push(redis = Redis.new()) end @closed = false end |
Instance Method Details
#destroy ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/xunch/connection/fiber_redis_pool.rb', line 29 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.
40 41 42 43 44 45 46 47 |
# File 'lib/xunch/connection/fiber_redis_pool.rb', line 40 def pool_status { close: @closed, available: @available.size, reserved: @reserved.size, pending: @pending.size } end |
#with ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/xunch/connection/fiber_redis_pool.rb', line 19 def with f = Fiber.current begin conn = checkout_redis(f) yield conn ensure checkin_redis(f) end end |