Skip to content

Commit

Permalink
Support reverse paging of sorted sets, #1098
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Feb 1, 2014
1 parent b0107b5 commit 81de381
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Changes.md
@@ -1,9 +1,10 @@
HEAD
2.17.4
-----------

- Fix JID support in inline testing, #1454
- Polish worker arguments display in UI, #1453
- Marshal arguments fully to avoid worker mutation, #1452
- Support reverse paging sorted sets, #1098


2.17.3
Expand Down
19 changes: 14 additions & 5 deletions lib/sidekiq/paginator.rb
@@ -1,6 +1,6 @@
module Sidekiq
module Paginator
def page(key, pageidx=1, page_size=25)
def page(key, pageidx=1, page_size=25, opts=nil)
current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
pageidx = current_page - 1
total_size = 0
Expand All @@ -13,11 +13,20 @@ def page(key, pageidx=1, page_size=25)

case type
when 'zset'
total_size = conn.zcard(key)
items = conn.zrange(key, starting, ending, :with_scores => true)
rev = opts.try(:[], :reverse)
total_size, items = conn.multi do
conn.zcard(key)
if rev
conn.zrevrange(key, starting, ending, :with_scores => true)
else
conn.zrange(key, starting, ending, :with_scores => true)
end
end
when 'list'
total_size = conn.llen(key)
items = conn.lrange(key, starting, ending)
total_size, items = conn.multi do
conn.llen(key)
conn.lrange(key, starting, ending)
end
when 'none'
return [1, 0, []]
else
Expand Down
2 changes: 1 addition & 1 deletion lib/sidekiq/version.rb
@@ -1,3 +1,3 @@
module Sidekiq
VERSION = "2.17.2"
VERSION = "2.17.4"
end

0 comments on commit 81de381

Please sign in to comment.