Sha256: 61b22cb3b0e12961538438e40ec829bb3c0eb6766199189509c45b660b3ab747

Contents?: true

Size: 788 Bytes

Versions: 52

Compression:

Stored size: 788 Bytes

Contents

module Sidekiq
  module Paginator
    def page(key, pageidx=1, page_size=25)
      current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i
      pageidx = current_page - 1
      total_size = 0
      items = []
      starting = pageidx * page_size
      ending = starting + page_size - 1

      Sidekiq.redis do |conn|
        type = conn.type(key)

        case type
        when 'zset'
          total_size = conn.zcard(key)
          items = conn.zrange(key, starting, ending, :with_scores => true)
        when 'list'
          total_size = conn.llen(key)
          items = conn.lrange(key, starting, ending)
        when 'none'
          return [1, 0, []]
        else
          raise "can't page a #{type}"
        end
      end

      [current_page, total_size, items]
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
sidekiq-2.17.3 lib/sidekiq/paginator.rb
sidekiq-2.17.2 lib/sidekiq/paginator.rb
sidekiq-2.17.1 lib/sidekiq/paginator.rb
sidekiq-2.17.0 lib/sidekiq/paginator.rb
sidekiq-2.16.1 lib/sidekiq/paginator.rb
sidekiq-2.16.0 lib/sidekiq/paginator.rb
sidekiq-2.15.2 lib/sidekiq/paginator.rb
sidekiq-2.15.1 lib/sidekiq/paginator.rb
sidekiq-2.15.0 lib/sidekiq/paginator.rb
sidekiq-2.14.1 lib/sidekiq/paginator.rb
sidekiq-2.14.0 lib/sidekiq/paginator.rb
sidekiq-2.13.1 lib/sidekiq/paginator.rb
sidekiq-2.13.0 lib/sidekiq/paginator.rb
sidekiq-2.12.4 lib/sidekiq/paginator.rb
sidekiq-2.12.3 lib/sidekiq/paginator.rb
sidekiq-2.12.1 lib/sidekiq/paginator.rb
sidekiq-2.12.0 lib/sidekiq/paginator.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/paginator.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/paginator.rb
sidekiq-2.11.2 lib/sidekiq/paginator.rb