mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 02:53:41 +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,22 +151,26 @@ class DiscourseRedis
|
||||||
end
|
end
|
||||||
|
|
||||||
def multi
|
def multi
|
||||||
if block_given?
|
DiscourseRedis.ignore_readonly do
|
||||||
@redis.multi do |transaction|
|
if block_given?
|
||||||
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
@redis.multi do |transaction|
|
||||||
|
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@redis.multi
|
||||||
end
|
end
|
||||||
else
|
|
||||||
@redis.multi
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def pipelined
|
def pipelined
|
||||||
if block_given?
|
DiscourseRedis.ignore_readonly do
|
||||||
@redis.pipelined do |transaction|
|
if block_given?
|
||||||
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
@redis.pipelined do |transaction|
|
||||||
|
yield DiscourseRedis.new(@config, namespace: @namespace, raw_redis: transaction)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
@redis.pipelined
|
||||||
end
|
end
|
||||||
else
|
|
||||||
@redis.pipelined
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
Block a user