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

Methods included from Script::Caller

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

Methods included from Logging

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



95
96
97
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 95

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
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 48

def exist?
  redis do |conn|
    value = conn.exists(key)

    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



85
86
87
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 85

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

#pttlInteger

The number of microseconds until the key expires

Returns:

  • (Integer)

    expiration in milliseconds



64
65
66
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 64

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

#ttlInteger

The number of seconds until the key expires

Returns:

  • (Integer)

    expiration in seconds



74
75
76
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 74

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