Class: Sidekiq::SortedSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sidekiq/api.rb

Direct Known Subclasses

JobSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ SortedSet

Returns a new instance of SortedSet.


547
548
549
550
# File 'lib/sidekiq/api.rb', line 547

def initialize(name)
  @name = name
  @_size = size
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


545
546
547
# File 'lib/sidekiq/api.rb', line 545

def name
  @name
end

Instance Method Details

#clearObject Also known as: 💣


567
568
569
570
571
# File 'lib/sidekiq/api.rb', line 567

def clear
  Sidekiq.redis do |conn|
    conn.del(name)
  end
end

#scan(match, count = 100) ⇒ Object


556
557
558
559
560
561
562
563
564
565
# File 'lib/sidekiq/api.rb', line 556

def scan(match, count = 100)
  return to_enum(:scan, match) unless block_given?

  match = "*#{match}*" unless match.include?("*")
  Sidekiq.redis do |conn|
    conn.zscan_each(name, match: match, count: count) do |entry, score|
      yield SortedEntry.new(self, score, entry)
    end
  end
end

#sizeObject


552
553
554
# File 'lib/sidekiq/api.rb', line 552

def size
  Sidekiq.redis { |c| c.zcard(name) }
end