Class: SidekiqUniqueJobs::Redis::SortedSet

Inherits:
Entity
  • Object
show all
Defined in:
lib/sidekiq_unique_jobs/redis/sorted_set.rb

Overview

Class SortedSet provides convenient access to redis sorted sets

Author:

Direct Known Subclasses

Changelog, Digests

Instance Attribute Summary

Attributes inherited from Entity

#key

Instance Method Summary collapse

Methods inherited from Entity

#exist?, #expires?, #initialize, #pttl, #ttl

Methods included from Timing

clock_stamp, now_f, time_source, timed

Methods included from JSON

dump_json, load_json

Methods included from Script::Caller

call_script, debug_lua, do_call, extract_args, max_history, now_f, redis_version

Methods included from Logging

included, #log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger, #logging_context, #with_configured_loggers_context, #with_logging_context

Constructor Details

This class inherits a constructor from SidekiqUniqueJobs::Redis::Entity

Instance Method Details

#countInteger

Returns the count for this sorted set

Returns:

  • (Integer)

    the number of entries



54
55
56
# File 'lib/sidekiq_unique_jobs/redis/sorted_set.rb', line 54

def count
  redis { |conn| conn.zcard(key) }
end

#entries(with_scores: true) ⇒ Array<Object>, Hash

Return entries for this sorted set

Parameters:

  • with_scores (true, false) (defaults to: true)

    true return

Returns:

  • (Array<Object>)

    when given with_scores: false

  • (Hash)

    when given with_scores: true



19
20
21
22
23
24
# File 'lib/sidekiq_unique_jobs/redis/sorted_set.rb', line 19

def entries(with_scores: true)
  entrys = redis { |conn| conn.zrange(key, 0, -1, with_scores: with_scores) }
  return entrys unless with_scores

  entrys.each_with_object({}) { |pair, hash| hash[pair[0]] = pair[1] }
end

#rank(member) ⇒ Integer

Return the zrak of the member

Parameters:

  • member (String)

    the member to pull rank on

Returns:

  • (Integer)


33
34
35
# File 'lib/sidekiq_unique_jobs/redis/sorted_set.rb', line 33

def rank(member)
  redis { |conn| conn.zrank(key, member) }
end

#score(member) ⇒ Integer, Float

Return score for a member

Parameters:

  • member (String)

    the member for which score

Returns:

  • (Integer, Float)


44
45
46
# File 'lib/sidekiq_unique_jobs/redis/sorted_set.rb', line 44

def score(member)
  redis { |conn| conn.zscore(key, member) }
end