class SidekiqUniqueJobs::Redis::Entity
Class Entity
functions as a base class for redis types
@author Mikael Henriksson <mikael@mhenrixon.com>
Attributes
@!attribute [r] key
@return [String] the redis key for this entity
Public Class Methods
Public Instance Methods
Source
# File lib/sidekiq_unique_jobs/redis/entity.rb, line 101 def count 0 end
Returns the number of entries in this entity
@return [Integer] 0
Source
# 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
Checks if the key for this entity exists in redis
@return [true] when exists @return [false] when not exists
Source
# File lib/sidekiq_unique_jobs/redis/entity.rb, line 91 def expires? pttl.positive? || ttl.positive? end
Check if the entity has expiration
@return [true] when entity is set to exire @return [false] when entity isn’t expiring
Source
# File lib/sidekiq_unique_jobs/redis/entity.rb, line 70 def pttl redis { |conn| conn.pttl(key) } end
The number of microseconds until the key expires
@return [Integer] expiration in milliseconds
Source
# File lib/sidekiq_unique_jobs/redis/entity.rb, line 80 def ttl redis { |conn| conn.ttl(key) } end
The number of seconds until the key expires
@return [Integer] expiration in seconds
Private Instance Methods
Source
# File lib/sidekiq_unique_jobs/redis/entity.rb, line 107 def boolean?(value) [TrueClass, FalseClass].any? { |klazz| value.is_a?(klazz) } end