module RedisCacheable::Connectable::ClassMethods
Public Instance Methods
redis(&blk)
click to toggle source
# File lib/redis_cacheable/connectable.rb, line 21 def redis(&blk) raise ArgumentError.new("Need block") unless blk connection = __ensure_redis_connection__ case connection when ConnectionPool connection.with do |conn| blk.call(__wrap_namespace__(conn)) end when Redis blk.call(__wrap_namespace__(connection)) else raise "Not redis connection" end end
redis_namespace()
click to toggle source
# File lib/redis_cacheable/connectable.rb, line 14 def redis_namespace config = RedisCacheable::Configuration.config namespace = [to_s.underscore] namespace.unshift config.namespace_prefix if config.namespace_prefix namespace.join("_") end
Private Instance Methods
__ensure_redis_connection__()
click to toggle source
# File lib/redis_cacheable/connectable.rb, line 39 def __ensure_redis_connection__ unless Connectable.redis_connection config = RedisCacheable::Configuration.config Connectable.redis_connection = ConnectionPool.new(size: config.pool_size, timeout: config.timeout) { Redis.new(host: config.host, port: config.port, driver: config.driver.to_sym) } end Connectable.redis_connection end
__wrap_namespace__(connection)
click to toggle source
# File lib/redis_cacheable/connectable.rb, line 50 def __wrap_namespace__(connection) Redis::Namespace.new(redis_namespace, redis: connection) end