class SidekiqUniqueJobs::Redis::Entity

Class Entity functions as a base class for redis types

@author Mikael Henriksson <mikael@mhenrixon.com>

Attributes

key[R]

@!attribute [r] key

@return [String] the redis key for this entity

Public Class Methods

new(key) click to toggle source

Initialize a new Entity

@param [String] key the redis key for this entity

# File lib/sidekiq_unique_jobs/redis/entity.rb, line 37
def initialize(key)
  @key = key
end

Public Instance Methods

count() click to toggle source

Returns the number of entries in this entity

@return [Integer] 0

# File lib/sidekiq_unique_jobs/redis/entity.rb, line 101
def count
  0
end
exist?() click to toggle source

Checks if the key for this entity exists in redis

@return [true] when exists @return [false] when not exists

# 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?() click to toggle source

Check if the entity has expiration

@return [true] when entity is set to exire @return [false] when entity isn't expiring

# File lib/sidekiq_unique_jobs/redis/entity.rb, line 91
def expires?
  pttl.positive? || ttl.positive?
end
pttl() click to toggle source

The number of microseconds until the key expires

@return [Integer] expiration in milliseconds

# File lib/sidekiq_unique_jobs/redis/entity.rb, line 70
def pttl
  redis { |conn| conn.pttl(key) }
end
ttl() click to toggle source

The number of seconds until the key expires

@return [Integer] expiration in seconds

# File lib/sidekiq_unique_jobs/redis/entity.rb, line 80
def ttl
  redis { |conn| conn.ttl(key) }
end

Private Instance Methods

boolean?(value) click to toggle source
# File lib/sidekiq_unique_jobs/redis/entity.rb, line 107
def boolean?(value)
  [TrueClass, FalseClass].any? { |klazz| value.is_a?(klazz) }
end