1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Remove instances of early return while holding a Redis connection

This commit is contained in:
Mike Perham 2015-04-10 14:28:28 -07:00
parent 4e5ce7da4e
commit cad13dad9b
2 changed files with 14 additions and 10 deletions

View file

@ -789,13 +789,15 @@ module Sidekiq
def size
Sidekiq.redis do |conn|
procs = conn.smembers('processes')
return 0 if procs.empty?
conn.pipelined do
procs.each do |key|
conn.hget(key, 'busy')
end
end.map(&:to_i).inject(:+)
if procs.empty?
0
else
conn.pipelined do
procs.each do |key|
conn.hget(key, 'busy')
end
end.map(&:to_i).inject(:+)
end
end
end
end

View file

@ -1,5 +1,6 @@
module Sidekiq
module Paginator
def page(key, pageidx=1, page_size=25, opts=nil)
current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
pageidx = current_page - 1
@ -22,19 +23,20 @@ module Sidekiq
conn.zrange(key, starting, ending, :with_scores => true)
end
end
[current_page, total_size, items]
when 'list'
total_size, items = conn.multi do
conn.llen(key)
conn.lrange(key, starting, ending)
end
[current_page, total_size, items]
when 'none'
return [1, 0, []]
[1, 0, []]
else
raise "can't page a #{type}"
end
end
[current_page, total_size, items]
end
end
end