DEV: Readonly Redis support for `DiscourseRedis#multi/pipelined` (#16744)
Follow-up to 2df3c65ba9
This commit is contained in:
parent
2cc9f0e7d9
commit
de9fe907ee
|
@ -151,6 +151,7 @@ class DiscourseRedis
|
||||||
end
|
end
|
||||||
|
|
||||||
def multi
|
def multi
|
||||||
|
DiscourseRedis.ignore_readonly do
|
||||||
if block_given?
|
if block_given?
|
||||||
@redis.multi do |transaction|
|
@redis.multi do |transaction|
|
||||||
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
||||||
|
@ -159,8 +160,10 @@ class DiscourseRedis
|
||||||
@redis.multi
|
@redis.multi
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def pipelined
|
def pipelined
|
||||||
|
DiscourseRedis.ignore_readonly do
|
||||||
if block_given?
|
if block_given?
|
||||||
@redis.pipelined do |transaction|
|
@redis.pipelined do |transaction|
|
||||||
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
||||||
|
@ -169,6 +172,7 @@ class DiscourseRedis
|
||||||
@redis.pipelined
|
@redis.pipelined
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,39 @@ describe DiscourseRedis do
|
||||||
|
|
||||||
expect(redis.get('foo')).to eq("baz")
|
expect(redis.get('foo')).to eq("baz")
|
||||||
expect(redis.get('baz')).to eq("1")
|
expect(redis.get('baz')).to eq("1")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should noop pipelined commands against a readonly redis' do
|
||||||
|
redis.without_namespace
|
||||||
|
.expects(:pipelined)
|
||||||
|
.raises(Redis::CommandError.new("READONLY"))
|
||||||
|
|
||||||
|
set, incr = nil
|
||||||
|
|
||||||
|
val = redis.pipelined do |pipeline|
|
||||||
|
set = pipeline.set "foo", "baz"
|
||||||
|
incr = pipeline.incr "baz"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(val).to eq(nil)
|
||||||
|
expect(redis.get('foo')).to eq(nil)
|
||||||
|
expect(redis.get('baz')).to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should noop multi commands against a readonly redis' do
|
||||||
|
redis.without_namespace
|
||||||
|
.expects(:multi)
|
||||||
|
.raises(Redis::CommandError.new("READONLY"))
|
||||||
|
|
||||||
|
val = redis.multi do |transaction|
|
||||||
|
transaction.set 'foo', 'bar'
|
||||||
|
transaction.set 'bar', 'foo'
|
||||||
|
transaction.get 'bar'
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(val).to eq(nil)
|
||||||
|
expect(redis.get('foo')).to eq(nil)
|
||||||
|
expect(redis.get('bar')).to eq(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue