Class: SidekiqUniqueJobs::Redis::Entity
- Inherits:
-
Object
- Object
- SidekiqUniqueJobs::Redis::Entity
- 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
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#count ⇒ Integer
Returns the number of entries in this entity.
-
#exist? ⇒ true, false
Checks if the key for this entity exists in redis.
-
#expires? ⇒ true, false
Check if the entity has expiration.
-
#initialize(key) ⇒ Entity
constructor
Initialize a new Entity.
-
#pttl ⇒ Integer
The number of microseconds until the key expires.
-
#ttl ⇒ Integer
The number of seconds until the key expires.
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
37 38 39 |
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 37 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object (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
#count ⇒ Integer
Returns the number of entries in this entity
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
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
91 92 93 |
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 91 def expires? pttl.positive? || ttl.positive? end |
#pttl ⇒ Integer
The number of microseconds until the key expires
70 71 72 |
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 70 def pttl redis { |conn| conn.pttl(key) } end |
#ttl ⇒ Integer
The number of seconds until the key expires
80 81 82 |
# File 'lib/sidekiq_unique_jobs/redis/entity.rb', line 80 def ttl redis { |conn| conn.ttl(key) } end |