lib/routemaster/redis_broker.rb in routemaster-drain-2.3.0 vs lib/routemaster/redis_broker.rb in routemaster-drain-2.4.0
- old
+ new
@@ -1,6 +1,7 @@
require 'redis-namespace'
+require 'redis/distributed'
require 'uri'
require 'singleton'
module Routemaster
class RedisBroker
@@ -9,17 +10,17 @@
def initialize
@_connections = {}
_cleanup
end
- def get(url)
+ def get(name, urls: [])
_check_for_fork
- @_connections[url] ||= begin
- parsed_url = URI.parse(url)
- namespace = parsed_url.path.split('/')[2] || 'rm'
- Redis::Namespace.new(namespace, redis: Redis.new(url: url))
- end
+ @_connections[name] ||= begin
+ parsed_url = URI.parse(urls.first)
+ namespace = parsed_url.path.split('/')[2] || 'rm'
+ Redis::Namespace.new(namespace, redis: Redis::Distributed.new(urls))
+ end
end
def cleanup
_cleanup
end
@@ -30,10 +31,10 @@
_cleanup unless Process.pid == @_pid
end
def _cleanup
@_pid = Process.pid
- @_connections.each_value(&:quit)
+ @_connections.each_value.map(&:redis).each(&:quit)
@_connections = {}
end
end
end