mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 03:15:48 +08:00
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
|
||||
|
||||
def multi
|
||||
DiscourseRedis.ignore_readonly do
|
||||
if block_given?
|
||||
@redis.multi do |transaction|
|
||||
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
||||
|
@ -159,8 +160,10 @@ class DiscourseRedis
|
|||
@redis.multi
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pipelined
|
||||
DiscourseRedis.ignore_readonly do
|
||||
if block_given?
|
||||
@redis.pipelined do |transaction|
|
||||
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
||||
|
@ -169,6 +172,7 @@ class DiscourseRedis
|
|||
@redis.pipelined
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -52,7 +52,39 @@ describe DiscourseRedis do
|
|||
|
||||
expect(redis.get('foo')).to eq("baz")
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user