Sha256: 49cba27baa4571f5eb483d33696f6af531ca2d5cbf4b30a2ecedf76bc2350ebc

Contents?: true

Size: 1.25 KB

Versions: 61

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  module Redis
    #
    # Class Hash provides convenient access to redis hashes
    #
    # @author Mikael Henriksson <mikael@mhenrixon.com>
    #
    class Hash < Entity
      #
      # Return entries for this hash
      #
      # @param [true,false] with_values false return hash
      #
      # @return [Array<Object>] when given with_values: false
      # @return [Hash<String, String>] when given with_values: true
      #
      def entries(with_values: false)
        if with_values
          redis { |conn| conn.hgetall(key) }
        else
          redis { |conn| conn.hkeys(key) }
        end
      end

      #
      # Removes the key from redis
      #
      def del(*fields)
        redis { |conn| conn.hdel(key, *fields) }
      end

      #
      # Get a members value
      #
      # @param [String] member the member who's value to get
      #
      # @return [Object] whatever is stored on this hash member
      #
      def [](member)
        redis { |conn| conn.hget(key, member) }
      end

      #
      # Returns the count for this hash
      #
      #
      # @return [Integer] the length of this hash
      #
      def count
        redis { |conn| conn.hlen(key) }
      end
    end
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.10 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.33 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.32 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.9 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.8 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.7 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.6 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.31 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.5 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.4 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.30 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.3 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-8.0.0 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.29 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.28 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.27 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.26 lib/sidekiq_unique_jobs/redis/hash.rb
sidekiq-unique-jobs-7.1.25 lib/sidekiq_unique_jobs/redis/hash.rb