DEV: Make DiscourseRedis#del support deleting multiple keys (#15905)

Redis supports deleting multiple keys at once using the `del` command and so does the `redis` gem: 21ec1dec06/lib/redis/commands/keys.rb (L188-L193). However, our wrapper around the `del` method currently accepts only one argument and expects it to be a string so it's impossible to delete multiple keys at once.

This PR changes the signature of the `DiscourseRedis#del` method so it accepts any number of arguments and makes sure all keys are properly namespaced before calling the `del` implementation of the `redis` gem.
This commit is contained in:
Osama Sayegh 2022-02-11 08:09:32 +03:00 committed by GitHub
parent 81791a821c
commit 1fc3cf0569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,10 +76,11 @@ class DiscourseRedis
DiscourseRedis.ignore_readonly { @redis.mget(*args) }
end
def del(k)
def del(*keys)
DiscourseRedis.ignore_readonly do
k = "#{namespace}:#{k}" if @namespace
@redis.del k
keys = keys.flatten(1)
keys.map! { |k| "#{namespace}:#{k}" } if @namespace
@redis.del(*keys)
end
end