Class: Sidekiq::SortedSet

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

Overview

Base class for all sorted sets within Sidekiq.

Direct Known Subclasses

JobSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

Redis key of the set



612
613
614
# File 'lib/sidekiq/api.rb', line 612

def name
  @name
end

#NameObject (readonly)

Redis key of the set



612
# File 'lib/sidekiq/api.rb', line 612

attr_reader :name

Instance Method Details

#clearBoolean Also known as: 💣

Returns always true.

Returns:

  • (Boolean)

    always true



644
645
646
647
648
649
# File 'lib/sidekiq/api.rb', line 644

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

#scan(match, count = 100) {|each| ... } ⇒ Object

Scan through each element of the sorted set, yielding each to the supplied block. Please see Redis’s <a href=“redis.io/commands/scan/”>SCAN documentation</a> for implementation details.

Parameters:

  • match (String)

    a snippet or regexp to filter matches.

  • count (Integer) (defaults to: 100)

    number of elements to retrieve at a time, default 100

Yield Parameters:



632
633
634
635
636
637
638
639
640
641
# File 'lib/sidekiq/api.rb', line 632

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

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

#sizeObject

real-time size of the set, will change



622
623
624
# File 'lib/sidekiq/api.rb', line 622

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