Commit 474ed146 authored by Robert May's avatar Robert May Committed by Stan Hu

Gracefully fall back to DEL

If UNLINK is not supported by the Redis server, we should
fall back to DEL. UNLINK was introduced in Redis 4.
parent 568905a0
...@@ -17,12 +17,7 @@ module Gitlab ...@@ -17,12 +17,7 @@ module Gitlab
def expire(*keys) def expire(*keys)
with do |redis| with do |redis|
keys = keys.map { |key| cache_key(key) } keys = keys.map { |key| cache_key(key) }
unlink_or_delete(redis, *keys)
if Feature.enabled?(:repository_set_cache_unlink, default_enabled: true)
redis.unlink(*keys)
else
redis.delete(*keys)
end
end end
end end
...@@ -59,5 +54,15 @@ module Gitlab ...@@ -59,5 +54,15 @@ module Gitlab
def with(&blk) def with(&blk)
Gitlab::Redis::Cache.with(&blk) # rubocop:disable CodeReuse/ActiveRecord Gitlab::Redis::Cache.with(&blk) # rubocop:disable CodeReuse/ActiveRecord
end end
def unlink_or_delete(redis, *keys)
if Feature.enabled?(:repository_set_cache_unlink, default_enabled: true)
redis.unlink(*keys)
else
redis.del(*keys)
end
rescue ::Redis::CommandError
redis.del(*keys)
end
end end
end end
...@@ -87,6 +87,17 @@ describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do ...@@ -87,6 +87,17 @@ describe Gitlab::RepositorySetCache, :clean_gitlab_redis_cache do
expect(cache.read(:bar)).to be_empty expect(cache.read(:bar)).to be_empty
end end
end end
context "unlink isn't supported" do
before do
allow_any_instance_of(Redis).to receive(:unlink) { raise ::Redis::CommandError }
end
it 'still deletes the given key' do
expect(cache.expire(:foo)).to eq(1)
expect(cache.read(:foo)).to be_empty
end
end
end end
describe '#exist?' do describe '#exist?' 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