Commit 4eda45c8 authored by Marc Shaw's avatar Marc Shaw

Switch from using SharedState to Cache for mergeability cache

MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/76755
parent 57aa5386
......@@ -7,13 +7,13 @@ module Gitlab
VERSION = 1
def save_check(merge_check:, result_hash:)
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::Cache.with do |redis|
redis.set(merge_check.cache_key + ":#{VERSION}", result_hash.to_json, ex: EXPIRATION)
end
end
def retrieve_check(merge_check:)
Gitlab::Redis::SharedState.with do |redis|
Gitlab::Redis::Cache.with do |redis|
Gitlab::Json.parse(redis.get(merge_check.cache_key + ":#{VERSION}"))
end
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Gitlab::MergeRequests::Mergeability::RedisInterface, :clean_gitlab_redis_shared_state do
RSpec.describe Gitlab::MergeRequests::Mergeability::RedisInterface, :clean_gitlab_redis_cache do
subject(:redis_interface) { described_class.new }
let(:merge_check) { double(cache_key: '13') }
......@@ -11,17 +11,17 @@ RSpec.describe Gitlab::MergeRequests::Mergeability::RedisInterface, :clean_gitla
describe '#save_check' do
it 'saves the hash' do
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(expected_key) }).to be_nil
expect(Gitlab::Redis::Cache.with { |redis| redis.get(expected_key) }).to be_nil
redis_interface.save_check(merge_check: merge_check, result_hash: result_hash)
expect(Gitlab::Redis::SharedState.with { |redis| redis.get(expected_key) }).to eq result_hash.to_json
expect(Gitlab::Redis::Cache.with { |redis| redis.get(expected_key) }).to eq result_hash.to_json
end
end
describe '#retrieve_check' do
it 'returns the hash' do
Gitlab::Redis::SharedState.with { |redis| redis.set(expected_key, result_hash.to_json) }
Gitlab::Redis::Cache.with { |redis| redis.set(expected_key, result_hash.to_json) }
expect(redis_interface.retrieve_check(merge_check: merge_check)).to eq result_hash
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