Commit f978b4ca authored by Sean McGivern's avatar Sean McGivern

Switch RedisCacheable to use Redis cache instance

This used the 'shared state' Redis due to an understandable
misunderstanding about the purpose of that. The shared state Redis is
for persistent data, and the cache Redis is for caching short-lived
data.

Despite the names, both the cache and the shared state instance are
available to all ways the Rails application is deployed (web nodes and
background job nodes in particular).
parent 3f0aae43
...@@ -26,7 +26,7 @@ module RedisCacheable ...@@ -26,7 +26,7 @@ module RedisCacheable
end end
def cache_attributes(values) def cache_attributes(values)
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::Cache.with do |redis|
redis.set(cache_attribute_key, values.to_json, ex: CACHED_ATTRIBUTES_EXPIRY_TIME) redis.set(cache_attribute_key, values.to_json, ex: CACHED_ATTRIBUTES_EXPIRY_TIME)
end end
...@@ -41,7 +41,7 @@ module RedisCacheable ...@@ -41,7 +41,7 @@ module RedisCacheable
def cached_attributes def cached_attributes
strong_memoize(:cached_attributes) do strong_memoize(:cached_attributes) do
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::Cache.with do |redis|
data = redis.get(cache_attribute_key) data = redis.get(cache_attribute_key)
JSON.parse(data, symbolize_names: true) if data JSON.parse(data, symbolize_names: true) if data
end end
......
...@@ -270,7 +270,7 @@ describe Ci::Runner do ...@@ -270,7 +270,7 @@ describe Ci::Runner do
it { is_expected.to eq([@runner2])} it { is_expected.to eq([@runner2])}
end end
describe '#online?' do describe '#online?', :clean_gitlab_redis_cache do
let(:runner) { create(:ci_runner, :instance) } let(:runner) { create(:ci_runner, :instance) }
subject { runner.online? } subject { runner.online? }
...@@ -332,7 +332,7 @@ describe Ci::Runner do ...@@ -332,7 +332,7 @@ describe Ci::Runner do
end end
def stub_redis_runner_contacted_at(value) def stub_redis_runner_contacted_at(value)
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::Cache.with do |redis|
cache_key = runner.send(:cache_attribute_key) cache_key = runner.send(:cache_attribute_key)
expect(redis).to receive(:get).with(cache_key) expect(redis).to receive(:get).with(cache_key)
.and_return({ contacted_at: value }.to_json).at_least(:once) .and_return({ contacted_at: value }.to_json).at_least(:once)
...@@ -640,7 +640,7 @@ describe Ci::Runner do ...@@ -640,7 +640,7 @@ describe Ci::Runner do
end end
def expect_redis_update def expect_redis_update
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::Cache.with do |redis|
redis_key = runner.send(:cache_attribute_key) redis_key = runner.send(:cache_attribute_key)
expect(redis).to receive(:set).with(redis_key, anything, any_args) expect(redis).to receive(:set).with(redis_key, anything, any_args)
end end
...@@ -664,7 +664,7 @@ describe Ci::Runner do ...@@ -664,7 +664,7 @@ describe Ci::Runner do
end end
it 'cleans up the queue' do it 'cleans up the queue' do
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::Cache.with do |redis|
expect(redis.get(queue_key)).to be_nil expect(redis.get(queue_key)).to be_nil
end end
end end
......
...@@ -31,7 +31,7 @@ describe RedisCacheable do ...@@ -31,7 +31,7 @@ describe RedisCacheable do
subject { instance.cached_attribute(payload.each_key.first) } subject { instance.cached_attribute(payload.each_key.first) }
it 'gets the cache attribute' do it 'gets the cache attribute' do
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::Cache.with do |redis|
expect(redis).to receive(:get).with(cache_key) expect(redis).to receive(:get).with(cache_key)
.and_return(payload.to_json) .and_return(payload.to_json)
end end
...@@ -44,7 +44,7 @@ describe RedisCacheable do ...@@ -44,7 +44,7 @@ describe RedisCacheable do
subject { instance.cache_attributes(payload) } subject { instance.cache_attributes(payload) }
it 'sets the cache attributes' do it 'sets the cache attributes' do
Gitlab::Redis::SharedState.with do |redis| Gitlab::Redis::Cache.with do |redis|
expect(redis).to receive(:set).with(cache_key, payload.to_json, anything) expect(redis).to receive(:set).with(cache_key, payload.to_json, anything)
end end
...@@ -52,7 +52,7 @@ describe RedisCacheable do ...@@ -52,7 +52,7 @@ describe RedisCacheable do
end end
end end
describe '#cached_attr_reader', :clean_gitlab_redis_shared_state do describe '#cached_attr_reader', :clean_gitlab_redis_cache do
subject { instance.name } subject { instance.name }
before do before do
......
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