diff options
author | Robert Speicher <robert@gitlab.com> | 2016-08-19 18:55:30 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-08-19 18:55:30 +0000 |
commit | 3043b31c458bf720843a84b35c9fbad5c1488c1d (patch) | |
tree | b90e1df74cc8c53c891f06912e65575fd0f2be48 | |
parent | 4f8e91fac043f09ea94a3542eeff9734db33645a (diff) | |
parent | ee684a0973b2f5fbb30fcf2f1b3099564ca15ac9 (diff) | |
download | gitlab-shell-3043b31c458bf720843a84b35c9fbad5c1488c1d.tar.gz |
Merge branch 'feature/redis-sentinel' into 'master'
v3.4.0
Sentinel Support
Sentinel connection parameters in `config.yml` file.
Fixes #29
See merge request !85
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | config.yml.example | 10 | ||||
-rw-r--r-- | lib/gitlab_net.rb | 6 | ||||
-rw-r--r-- | spec/fixtures/gitlab_config_redis.yml | 12 | ||||
-rw-r--r-- | spec/gitlab_config_spec.rb | 14 | ||||
-rw-r--r-- | spec/gitlab_net_spec.rb | 22 |
7 files changed, 46 insertions, 23 deletions
@@ -1,3 +1,6 @@ +v3.4.0 + - Redis Sentinel support + v3.3.3 - Print URL for new or existing merge request after push @@ -1 +1 @@ -3.3.3 +3.4.0 diff --git a/config.yml.example b/config.yml.example index 166e384..cd66022 100644 --- a/config.yml.example +++ b/config.yml.example @@ -38,8 +38,16 @@ redis: # port: 6379 # pass: redispass # Allows you to specify the password for Redis database: 0 - socket: /var/run/redis/redis.sock # Comment out this line if you want to use TCP + socket: /var/run/redis/redis.sock # Comment out this line if you want to use TCP or Sentinel namespace: resque:gitlab + # sentinels: + # - + # host: 127.0.0.1 + # port: 26380 + # - + # host: 127.0.0.1 + # port: 26381 + # Log file. # Default is gitlab-shell.log in the root directory. diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb index c06ed1e..35a8833 100644 --- a/lib/gitlab_net.rb +++ b/lib/gitlab_net.rb @@ -81,6 +81,12 @@ class GitlabNet db: database } + if redis_config.has_key?('sentinels') + params[:sentinels] = redis_config['sentinels'] + .select { |s| s['host'] && s['port'] } + .map { |s| { host: s['host'], port: s['port'] } } + end + if redis_config.has_key?("socket") params = { path: redis_config['socket'], db: database } elsif redis_config.has_key?("pass") diff --git a/spec/fixtures/gitlab_config_redis.yml b/spec/fixtures/gitlab_config_redis.yml new file mode 100644 index 0000000..e07e5df --- /dev/null +++ b/spec/fixtures/gitlab_config_redis.yml @@ -0,0 +1,12 @@ +redis: + bin: /usr/bin/redis-cli + host: 127.0.1.1 + port: 6378 + pass: secure + database: 1 + socket: /var/run/redis/redis.sock + namespace: my:gitlab + sentinels: + - + host: 127.0.0.1 + port: 26380 diff --git a/spec/gitlab_config_spec.rb b/spec/gitlab_config_spec.rb index 6c1af85..b92da65 100644 --- a/spec/gitlab_config_spec.rb +++ b/spec/gitlab_config_spec.rb @@ -6,17 +6,8 @@ describe GitlabConfig do describe :redis do before do - config.instance_variable_set(:@config, YAML.load(<<eos -redis: - bin: /usr/bin/redis-cli - host: 127.0.1.1 - port: 6378 - pass: secure - database: 1 - socket: /var/run/redis/redis.sock - namespace: my:gitlab -eos - )) + config_file = File.read('spec/fixtures/gitlab_config_redis.yml') + config.instance_variable_set(:@config, YAML.load(config_file)) end it { config.redis['bin'].should eq('/usr/bin/redis-cli') } @@ -26,6 +17,7 @@ eos it { config.redis['namespace'].should eq('my:gitlab') } it { config.redis['socket'].should eq('/var/run/redis/redis.sock') } it { config.redis['pass'].should eq('secure') } + it { config.redis['sentinels'].should eq([{ 'host' => '127.0.0.1', 'port' => 26380 }]) } end describe :gitlab_url do diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb index 2bbf98b..d4585d2 100644 --- a/spec/gitlab_net_spec.rb +++ b/spec/gitlab_net_spec.rb @@ -276,32 +276,34 @@ describe GitlabNet, vcr: true do expect_any_instance_of(Redis).to receive(:initialize).with({ host: '127.0.0.1', port: 6379, - db: 0 }).and_call_original + db: 0 }) gitlab_net.redis_client end end - context "with host and port" do - it 'uses the specified host and port' do + context "with password" do + it 'uses the specified host, port, and password' do allow(gitlab_net).to receive(:config).and_return(config) - allow(config).to receive(:redis).and_return( { 'host' => 'localhost', 'port' => 1123 } ) + allow(config).to receive(:redis).and_return( { 'host' => 'localhost', 'port' => 1123, 'pass' => 'secret' } ) expect_any_instance_of(Redis).to receive(:initialize).with({ host: 'localhost', port: 1123, - db: 0 }).and_call_original + db: 0, + password: 'secret'}) gitlab_net.redis_client end end - context "with password" do - it 'uses the specified host, port, and password' do + context "with sentinels" do + it 'uses the specified sentinels' do allow(gitlab_net).to receive(:config).and_return(config) - allow(config).to receive(:redis).and_return( { 'host' => 'localhost', 'port' => 1123, 'pass' => 'secret' } ) + allow(config).to receive(:redis).and_return({ 'host' => 'localhost', 'port' => 1123, + 'sentinels' => [{'host' => '127.0.0.1', 'port' => 26380}] }) expect_any_instance_of(Redis).to receive(:initialize).with({ host: 'localhost', port: 1123, db: 0, - password: 'secret'}).and_call_original + sentinels: [{host: '127.0.0.1', port: 26380}] }) gitlab_net.redis_client end end @@ -314,7 +316,7 @@ describe GitlabNet, vcr: true do allow(gitlab_net).to receive(:config).and_return(config) allow(config).to receive(:redis).and_return( { 'socket' => socket }) - expect_any_instance_of(Redis).to receive(:initialize).with({ path: socket, db: 0 }).and_call_original + expect_any_instance_of(Redis).to receive(:initialize).with({ path: socket, db: 0 }) gitlab_net.redis_client end end |