lib/modis.rb in modis-4.3.0 vs lib/modis.rb in modis-4.3.1
- old
+ new
@@ -16,27 +16,43 @@
require 'modis/finder'
require 'modis/index'
require 'modis/model'
module Modis
- @mutex = Mutex.new
class << self
attr_writer :connection_pool_size, :connection_pool_timeout,
:connection_pools
+ def mutex
+ @mutex ||= Mutex.new
+ end
+
def redis_options
@redis_options ||= { default: {} }
end
def redis_options=(options)
if options.is_a?(Hash) && options.values.first.is_a?(Hash)
@redis_options = options.transform_values(&:dup)
else
- @redis_options[:default] = options
+ redis_options[:default] = options
end
end
+ def reset!
+ connection_pools.each do |key, _|
+ with_connection(key) do |connection|
+ keys = connection.keys "#{config.namespace}:*"
+ connection.del(*keys) unless keys.empty?
+ end
+ end
+ instance_variables.each do |var|
+ instance_variable_set(var, nil)
+ remove_instance_variable(var)
+ end
+ end
+
def connection_pool_size
@connection_pool_size ||= 5
end
def connection_pool_timeout
@@ -47,10 +63,10 @@
@connection_pools ||= {}
end
def connection_pool(pool_name = :default)
connection_pools[pool_name] ||= begin
- @mutex.synchronize do
+ mutex.synchronize do
ConnectionPool.new(
size: connection_pool_size,
timeout: connection_pool_timeout
) do
Redis.new(redis_options[pool_name])