Sha256: f96b14ae828af96525c256b25ea76b3d35cb8a970d782942fbc956057f365a18

Contents?: true

Size: 1.39 KB

Versions: 24

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  module Redis
    #
    # Class SortedSet provides convenient access to redis sorted sets
    #
    # @author Mikael Henriksson <mikael@zoolutions.se>
    #
    class SortedSet < Entity
      #
      # Return entries for this sorted set
      #
      # @param [true,false] with_scores true return
      #
      # @return [Array<Object>] when given with_scores: false
      # @return [Hash] when given with_scores: true
      #
      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

      #
      # Return the zrak of the member
      #
      # @param [String] member the member to pull rank on
      #
      # @return [Integer]
      #
      def rank(member)
        redis { |conn| conn.zrank(key, member) }
      end

      #
      # Return score for a member
      #
      # @param [String] member the member for which score
      #
      # @return [Integer, Float]
      #
      def score(member)
        redis { |conn| conn.zscore(key, member) }
      end

      #
      # Returns the count for this sorted set
      #
      #
      # @return [Integer] the number of entries
      #
      def count
        redis { |conn| conn.zcard(key) }
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta25 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta24 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta23 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta22 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta21 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta20 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta19 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta18 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta17 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta16 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta15 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta14 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta13 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta12 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta11 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta10 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta9 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta8 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta7 lib/sidekiq_unique_jobs/redis/sorted_set.rb
sidekiq-unique-jobs-7.0.0.beta6 lib/sidekiq_unique_jobs/redis/sorted_set.rb