Sha256: b4cb9d7af4c3c75744fb781217cab2fa065014bac23972f7354c4a1330d0f2c9
Contents?: true
Size: 1.39 KB
Versions: 5
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@mhenrixon.com> # 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
5 entries across 5 versions & 1 rubygems