Skip to content

A platform for community discussion. Free, open, simple.

DEV: Fix implementation for `DiscourseRedis#exists`.

Guo Xiang Tan389bdcf5ab1b
diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb
index 5ef5de9ce9d..e273810a3c7 100644
--- a/lib/discourse_redis.rb
+++ b/lib/discourse_redis.rb
@@ -208,13 +208,15 @@ class DiscourseRedis
end
end
- # Remove when this has been upstreamed in https://github.com/redis/redis-rb/pull/911
+ # Implement our own because https://github.com/redis/redis-rb/issues/698 has stalled
def exists(*keys)
keys.map! { |a| "#{namespace}:#{a}" } if @namespace
DiscourseRedis.ignore_readonly do
- @redis._client.call([:exists, *keys]) do |value|
- value > 0
+ @redis.synchronize do |client|
+ client.call([:exists, *keys]) do |value|
+ value > 0
+ end
end
end
end
diff --git a/spec/components/discourse_redis_spec.rb b/spec/components/discourse_redis_spec.rb
index 059e1449628..8e4411653bd 100644
--- a/spec/components/discourse_redis_spec.rb
+++ b/spec/components/discourse_redis_spec.rb
@@ -88,7 +88,6 @@ describe DiscourseRedis do
end
end
- # Remove when this has been upstreamed in https://github.com/redis/redis-rb/pull/911
describe '.exists' do
it 'should return false when key is not present' do
expect(Discourse.redis.exists('test')).to eq(false)