Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2016-03-16 20:10:03 +0300
committerJacob Vosmaer <contact@jacobvosmaer.nl>2016-04-04 18:00:09 +0300
commit0163e27631fb993bd3541c09a95f0ef5e2026455 (patch)
treeb63cff41fe7d6e7433ecacfefd8be17e4fa29422 /lib/gitlab/redis.rb
parentba7fcc9866588eb215fc69f5d8b73c77805e4eef (diff)
Add Gitlab::Redis connection pool
Diffstat (limited to 'lib/gitlab/redis.rb')
-rw-r--r--lib/gitlab/redis.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/gitlab/redis.rb b/lib/gitlab/redis.rb
new file mode 100644
index 00000000000..d03e6e4cd92
--- /dev/null
+++ b/lib/gitlab/redis.rb
@@ -0,0 +1,35 @@
+module Gitlab
+ class Redis
+ attr_reader :url
+
+ def self.url
+ @url ||= new.url
+ end
+
+ def self.with
+ @pool ||= ConnectionPool.new { ::Redis.new(url: url) }
+ @pool.with { |redis| yield redis }
+ end
+
+ def self.redis_store_options
+ url = new.url
+ redis_config_hash = ::Redis::Store::Factory.extract_host_options_from_uri(url)
+ # Redis::Store does not handle Unix sockets well, so let's do it for them
+ redis_uri = URI.parse(url)
+ if redis_uri.scheme == 'unix'
+ redis_config_hash[:path] = redis_uri.path
+ end
+ redis_config_hash
+ end
+
+ def initialize(rails_env=nil)
+ rails_env ||= Rails.env
+ config_file = File.expand_path('../../../config/resque.yml', __FILE__)
+
+ @url = "redis://localhost:6379"
+ if File.exists?(config_file)
+ @url =YAML.load_file(config_file)[rails_env]
+ end
+ end
+ end
+end