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
end
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)
end
......@@ -41,7 +41,7 @@ module RedisCacheable
def cached_attributes
strong_memoize(:cached_attributes) do
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::Cache.with do |redis|
data = redis.get(cache_attribute_key)
JSON.parse(data, symbolize_names: true) if data
end
......
......@@ -270,7 +270,7 @@ describe Ci::Runner do
it { is_expected.to eq([@runner2])}
end
describe '#online?' do
describe '#online?', :clean_gitlab_redis_cache do
let(:runner) { create(:ci_runner, :instance) }
subject { runner.online? }
......@@ -332,7 +332,7 @@ describe Ci::Runner do
end
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)
expect(redis).to receive(:get).with(cache_key)
.and_return({ contacted_at: value }.to_json).at_least(:once)
......@@ -640,7 +640,7 @@ describe Ci::Runner do
end
def expect_redis_update
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::Cache.with do |redis|
redis_key = runner.send(:cache_attribute_key)
expect(redis).to receive(:set).with(redis_key, anything, any_args)
end
......@@ -664,7 +664,7 @@ describe Ci::Runner do
end
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
end
end
......
......@@ -31,7 +31,7 @@ describe RedisCacheable do
subject { instance.cached_attribute(payload.each_key.first) }
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)
.and_return(payload.to_json)
end
......@@ -44,7 +44,7 @@ describe RedisCacheable do
subject { instance.cache_attributes(payload) }
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)
end
......@@ -52,7 +52,7 @@ describe RedisCacheable do
end
end
describe '#cached_attr_reader', :clean_gitlab_redis_shared_state do
describe '#cached_attr_reader', :clean_gitlab_redis_cache do
subject { instance.name }
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