Commit ed0a7c25 authored by Gabriel Mazetto's avatar Gabriel Mazetto

Small refactor in Redis class and improved specs

parent ce41b5c7
......@@ -19,7 +19,7 @@ module Gitlab
class << self
def params
PARAMS_MUTEX.synchronize { new.params }
@params || PARAMS_MUTEX.synchronize { @params = new.params }
end
# @deprecated Use .params instead to get sentinel support
......@@ -35,6 +35,10 @@ module Gitlab
end
@pool.with { |redis| yield redis }
end
def reset_params!
@params = nil
end
end
def initialize(rails_env = nil)
......
# redis://[:password@]host[:port][/db-number][?option=value]
# more details: http://www.iana.org/assignments/uri-schemes/prov/redis
development:
url: redis://:mypassword@localhost:6379/99
url: redis://:mynewpassword@localhost:6379/99
sentinels:
-
host: localhost
......@@ -10,7 +10,7 @@ development:
host: slave2
port: 26381 # point to sentinel, not to redis port
test:
url: redis://:mypassword@localhost:6379/99
url: redis://:mynewpassword@localhost:6379/99
sentinels:
-
host: localhost
......@@ -19,7 +19,7 @@ test:
host: slave2
port: 26381 # point to sentinel, not to redis port
production:
url: redis://:mypassword@localhost:6379/99
url: redis://:mynewpassword@localhost:6379/99
sentinels:
-
host: slave1
......
development: unix:/path/to/redis.sock
test: unix:/path/to/redis.sock
production: unix:/path/to/redis.sock
development: unix:/path/to/old/redis.sock
test: unix:/path/to/old/redis.sock
production: unix:/path/to/old/redis.sock
......@@ -3,6 +3,9 @@ require 'spec_helper'
describe Gitlab::Redis do
let(:redis_config) { Rails.root.join('config', 'resque.yml').to_s }
before(:each) { described_class.reset_params! }
after(:each) { described_class.reset_params! }
describe '.params' do
subject { described_class.params }
......@@ -14,7 +17,7 @@ describe Gitlab::Redis do
it 'returns path key instead' do
expect_any_instance_of(described_class).to receive(:config_file) { config_old }
is_expected.to include(path: '/path/to/redis.sock')
is_expected.to include(path: '/path/to/old/redis.sock')
is_expected.not_to have_key(:url)
end
end
......@@ -46,7 +49,7 @@ describe Gitlab::Redis do
it 'returns hash with host, port, db, and password' do
expect_any_instance_of(described_class).to receive(:config_file) { config_new }
is_expected.to include(host: 'localhost', password: 'mypassword', port: 6379, db: 99)
is_expected.to include(host: 'localhost', password: 'mynewpassword', port: 6379, db: 99)
is_expected.not_to have_key(:url)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment