Skip to content

Commit

Permalink
Improve redis configuration.
Browse files Browse the repository at this point in the history
* Use environment variable REDIS_URL or config.yml
* Replace config keys socket, host, port with url
  • Loading branch information
amtrack committed Oct 11, 2014
1 parent 7e74d05 commit 1e7d3bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion config.yml.example
Expand Up @@ -28,11 +28,13 @@ auth_file: "/home/git/.ssh/authorized_keys"
# Redis settings used for pushing commit notices to gitlab
redis:
bin: /usr/bin/redis-cli
url: unix:/var/run/redis/redis.sock # Comment out this line if you want to use TCP
# url: redis://127.0.0.1:6379
# host: 127.0.0.1
# port: 6379
# pass: redispass # Allows you to specify the password for Redis
# socket: /var/run/redis/redis.sock
database: 0
socket: /var/run/redis/redis.sock # Comment out this line if you want to use TCP
namespace: resque:gitlab

# Log file.
Expand Down
26 changes: 18 additions & 8 deletions lib/gitlab_config.rb
@@ -1,4 +1,5 @@
require 'yaml'
require 'uri'

class GitlabConfig
attr_reader :config
Expand Down Expand Up @@ -29,6 +30,17 @@ def http_settings

def redis
@config['redis'] ||= {}
# backwards compatibility
if @config['redis']['host'] && @config['redis']['port']
@config['redis']['url'] = "redis://#{@config['redis']['host']}:@config['redis']['port']"
elsif @config['redis']['socket']
@config['redis']['url'] = "unix:/#{@config['redis']['socket']}"
end
if ENV['REDIS_URL']
@config['redis']['url'] = ENV['REDIS_URL']
end
@config['redis']['database'] ||= 0
@config['redis']
end

def redis_namespace
Expand All @@ -49,21 +61,19 @@ def audit_usernames

# Build redis command to write update event in gitlab queue
def redis_command
if redis.empty?
if not redis.url
# Default to old method of connecting to redis
# for users that haven't updated their configuration
%W(env -i redis-cli)
else
redis['database'] ||= 0
redis['host'] ||= '127.0.0.1'
redis['port'] ||= '6379'
if redis.has_key?("socket")
%W(#{redis['bin']} -s #{redis['socket']} -n #{redis['database']})
redis_url = URI.parse(redis.url)
if redis_url.scheme == 'unix'
%W(#{redis['bin']} -s #{redis_url.path} -n #{redis['database']})
else
if redis.has_key?("pass")
%W(#{redis['bin']} -h #{redis['host']} -p #{redis['port']} -n #{redis['database']} -a #{redis['pass']})
%W(#{redis['bin']} -h #{redis_url.host} -p #{redis_url.port} -n #{redis['database']} -a #{redis['pass']})
else
%W(#{redis['bin']} -h #{redis['host']} -p #{redis['port']} -n #{redis['database']})
%W(#{redis['bin']} -h #{redis_url.host} -p #{redis_url.port} -n #{redis['database']})
end
end
end
Expand Down

0 comments on commit 1e7d3bd

Please sign in to comment.