2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
module Gitlab
|
|
|
|
module MergeRequests
|
|
|
|
module Mergeability
|
|
|
|
class RedisInterface
|
|
|
|
EXPIRATION = 6.hours
|
|
|
|
VERSION = 1
|
|
|
|
|
|
|
|
def save_check(merge_check:, result_hash:)
|
2023-01-13 00:05:48 +05:30
|
|
|
with_redis do |redis|
|
2021-11-18 22:05:49 +05:30
|
|
|
redis.set(merge_check.cache_key + ":#{VERSION}", result_hash.to_json, ex: EXPIRATION)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def retrieve_check(merge_check:)
|
2023-01-13 00:05:48 +05:30
|
|
|
with_redis do |redis|
|
|
|
|
Gitlab::Json.parse(redis.get(merge_check.cache_key + ":#{VERSION}"), symbolize_keys: true)
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|
2023-01-13 00:05:48 +05:30
|
|
|
|
|
|
|
def with_redis(&block)
|
|
|
|
Gitlab::Redis::Cache.with(&block) # rubocop:disable CodeReuse/ActiveRecord
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|