Class: SidekiqUniqueJobs::Redis::Entity

Inherits:
Object
  • Object
show all
Includes:
JSON, Logging, Script::Caller, Timing
Defined in:
lib/sidekiq_unique_jobs/redis/entity.rb

Overview

Class Entity functions as a base class for redis types

Author:

Direct Known Subclasses

Hash, List, Set, SortedSet, String

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#initialize(key) ⇒ Entity

Initialize a new Entity

Parameters:

  • key (String)

    the redis key for this entity



37
38
39
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 37

def initialize(key)
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

#countInteger

Returns the number of entries in this entity

Returns:

  • (Integer)

    0



101
102
103
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 101

def count
  0
end

#exist?true, false

Checks if the key for this entity exists in redis

Returns:

  • (true)

    when exists

  • (false)

    when not exists



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 48

def exist?
  redis do |conn|
    # TODO: Remove the if statement in the future
    value =
      if conn.respond_to?(:exists?)
        conn.exists?(key)
      else
        conn.exists(key)
      end

    return value if boolean?(value)

    value.to_i.positive?
  end
end

#expires?true, false

Check if the entity has expiration

Returns:

  • (true)

    when entity is set to exire

  • (false)

    when entity isn’t expiring



91
92
93
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 91

def expires?
  pttl.positive? || ttl.positive?
end

#pttlInteger

The number of microseconds until the key expires

Returns:

  • (Integer)

    expiration in milliseconds



70
71
72
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 70

def pttl
  redis { |conn| conn.pttl(key) }
end

#ttlInteger

The number of seconds until the key expires

Returns:

  • (Integer)

    expiration in seconds



80
81
82
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 80

def ttl
  redis { |conn| conn.ttl(key) }
end