FIX: Topic view not working when Redis is readonly.

This commit is contained in:
Guo Xiang Tan 2016-03-03 08:26:45 +08:00
parent 5f4075a6cf
commit 5f8e20aa1d
2 changed files with 13 additions and 1 deletions

View File

@ -47,7 +47,12 @@ class RandomTopicSelector
$redis.ltrim(key, count, -1)
end
results = results[0]
if !results.is_a?(Array) # Redis is in readonly mode
results = $redis.lrange(key, 0, count-1)
else
results = results[0]
end
results.map!(&:to_i)
left = count - results.length

View File

@ -11,8 +11,15 @@ describe RandomTopicSelector do
$redis.rpush key, t
end
expect(RandomTopicSelector.next(0)).to eq([])
expect(RandomTopicSelector.next(2)).to eq([0,1])
$redis.expects(:multi).returns(Discourse.received_readonly!)
expect(RandomTopicSelector.next(2)).to eq([2,3])
$redis.unstub(:multi)
expect(RandomTopicSelector.next(2)).to eq([2,3])
expect(RandomTopicSelector.next(2)).to eq([])
end
it 'can correctly backfill' do