Class: SidekiqUniqueJobs::Redis::Hash

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

Overview

Class Hash provides convenient access to redis hashes

Author:

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, safe_load_json

Methods included from Script::Caller

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

Methods included from Logging

#build_message, 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

#[](member) ⇒ Object

Get a members value

Parameters:

  • member (String)

    the member who’s value to get

Returns:

  • (Object)

    whatever is stored on this hash member



41
42
43
# File 'lib/sidekiq_unique_jobs/redis/hash.rb', line 41

def [](member)
  redis { |conn| conn.hget(key, member) }
end

#countInteger

Returns the count for this hash

Returns:

  • (Integer)

    the length of this hash



51
52
53
# File 'lib/sidekiq_unique_jobs/redis/hash.rb', line 51

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

#del(*fields) ⇒ Object

Removes the key from redis



30
31
32
# File 'lib/sidekiq_unique_jobs/redis/hash.rb', line 30

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

#entries(with_values: false) ⇒ Array<Object>, Hash<String, String>

Return entries for this hash

Parameters:

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

    false return hash

Returns:

  • (Array<Object>)

    when given with_values: false

  • (Hash<String, String>)

    when given with_values: true



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

def entries(with_values: false)
  if with_values
    redis { |conn| conn.hgetall(key) }
  else
    redis { |conn| conn.hkeys(key) }
  end
end