Class: Redis::Rack::Connection
- Inherits:
-
Object
- Object
- Redis::Rack::Connection
- Defined in:
- lib/redis/rack/connection.rb
Constant Summary collapse
- POOL_KEYS =
%i[pool pool_size pool_timeout].freeze
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #pool ⇒ Object
- #pool_options ⇒ Object
- #pooled? ⇒ Boolean
- #store ⇒ Object
- #with(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/redis/rack/connection.rb', line 6 def initialize( = {}) @options = @store = [:redis_store] @pool = [:pool] if @pool && !@pool.is_a?(ConnectionPool) raise ArgumentError, "pool must be an instance of ConnectionPool" end if @store && !@store.is_a?(Redis::Store) raise ArgumentError, "redis_store must be an instance of Redis::Store (currently #{@store.class.name})" end end |
Instance Method Details
#pool ⇒ Object
34 35 36 |
# File 'lib/redis/rack/connection.rb', line 34 def pool @pool ||= ConnectionPool.new() { store } if pooled? end |
#pool_options ⇒ Object
42 43 44 45 46 47 |
# File 'lib/redis/rack/connection.rb', line 42 def { size: @options[:pool_size], timeout: @options[:pool_timeout] }.reject { |key, value| value.nil? }.to_h end |
#pooled? ⇒ Boolean
28 29 30 31 32 |
# File 'lib/redis/rack/connection.rb', line 28 def pooled? return @pooled if defined?(@pooled) @pooled = POOL_KEYS.any? { |key| @options.key?(key) } end |
#store ⇒ Object
38 39 40 |
# File 'lib/redis/rack/connection.rb', line 38 def store @store ||= Redis::Store::Factory.create(@options[:redis_server]) end |
#with(&block) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/redis/rack/connection.rb', line 20 def with(&block) if pooled? pool.with(&block) else block.call(store) end end |