Skip to content

Commit

Permalink
Remove instances of early return while holding a Redis connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Apr 10, 2015
1 parent 4e5ce7d commit cad13da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 9 additions & 7 deletions lib/sidekiq/api.rb
Expand Up @@ -789,13 +789,15 @@ def each
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
Expand Down
8 changes: 5 additions & 3 deletions lib/sidekiq/paginator.rb
@@ -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
Expand All @@ -22,19 +23,20 @@ def page(key, pageidx=1, page_size=25, opts=nil)
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

0 comments on commit cad13da

Please sign in to comment.