Class: RediConn::RedisConnection
- Inherits:
-
ConnectionPool
- Object
- ConnectionPool
- RediConn::RedisConnection
- Defined in:
- lib/rediconn/redis_connection.rb
Constant Summary collapse
- KNOWN_REDIS_URL_ENVS =
%w[REDIS_URL REDISTOGO_URL REDISCLOUD_URL].freeze
Class Method Summary collapse
- .configured?(prefix, explicit: true) ⇒ Boolean
- .create(raw_options = {}) ⇒ Object
- .shared_pools ⇒ Object
Instance Method Summary collapse
-
#lazy ⇒ Object
Mainly intended for console use.
- #lazy_with(&blk) ⇒ Object
-
#resize!(new_size) ⇒ Object
Very naughty, but looking at the source, should be safe.
Class Method Details
.configured?(prefix, explicit: true) ⇒ Boolean
14 15 16 |
# File 'lib/rediconn/redis_connection.rb', line 14 def configured?(prefix, explicit: true) determine_redis_provider(prefix: prefix, explicit: explicit).present? end |
.create(raw_options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rediconn/redis_connection.rb', line 22 def create( = {}) = .transform_keys(&:to_sym) if ![:url] && (u = determine_redis_provider(prefix: [:env_prefix])) [:url] = u end [:timeout] ||= 1 [:size] ||= if [:env_prefix] && (v = ENV["#{[:env_prefix]}_REDIS_POOL_SIZE"]) Integer(v) elsif ENV["RAILS_MAX_THREADS"] Integer(ENV["RAILS_MAX_THREADS"]) else 5 end if [:dedicated] initialize_pool() else url = [:url] cpool = shared_pools[url] ||= initialize_pool() cpool.resize!([:size]) # TODO Would be nice to respect timeouts cpool end end |
.shared_pools ⇒ Object
18 19 20 |
# File 'lib/rediconn/redis_connection.rb', line 18 def shared_pools @shared_pools ||= {} end |
Instance Method Details
#lazy ⇒ Object
Mainly intended for console use
123 124 125 126 127 |
# File 'lib/rediconn/redis_connection.rb', line 123 def lazy RedisProxy.new do |&blk| with(&blk) end end |
#lazy_with(&blk) ⇒ Object
129 130 131 132 |
# File 'lib/rediconn/redis_connection.rb', line 129 def lazy_with(&blk) return lazy unless blk with(&blk) end |
#resize!(new_size) ⇒ Object
Very naughty, but looking at the source, should be safe
135 136 137 138 139 |
# File 'lib/rediconn/redis_connection.rb', line 135 def resize!(new_size) return unless new_size > @size @size = new_size @available.instance_variable_set(:@max, new_size) end |