module Rediska::Databases::Expiring::InstanceMethods

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/rediska/databases/expiring.rb, line 12
def initialize
  super

  @expires = {}
end

Public Instance Methods

[](key) click to toggle source
Calls superclass method
# File lib/rediska/databases/expiring.rb, line 18
def [](key)
  key = normalize(key)
  delete(key) if expired?(key)

  super
end
[]=(key, val) click to toggle source
Calls superclass method
# File lib/rediska/databases/expiring.rb, line 25
def []=(key, val)
  key = normalize(key)
  expire(key)

  super
end
delete(key) click to toggle source
Calls superclass method
# File lib/rediska/databases/expiring.rb, line 32
def delete(key)
  key = normalize(key)
  expire(key)

  super
end
expire(key) click to toggle source
# File lib/rediska/databases/expiring.rb, line 39
def expire(key)
  key = normalize(key)
  expires.delete(key)
end
expired?(key) click to toggle source
# File lib/rediska/databases/expiring.rb, line 44
def expired?(key)
  key = normalize(key)
  expires.include?(key) && expires[key] <= Time.now
end
key?(key) click to toggle source
Calls superclass method
# File lib/rediska/databases/expiring.rb, line 49
def key?(key)
  key = normalize(key)
  delete(key) if expired?(key)

  super
end
keys() click to toggle source
Calls superclass method
# File lib/rediska/databases/expiring.rb, line 65
def keys
  super.select do |key|
    key = normalize(key)

    if expired?(key)
      delete(key)
      false
    else
      true
    end
  end
end
normalize(key) click to toggle source
# File lib/rediska/databases/expiring.rb, line 78
def normalize(key)
  key.to_s
end
values_at(*keys) click to toggle source
Calls superclass method
# File lib/rediska/databases/expiring.rb, line 56
def values_at(*keys)
  keys.each do |key|
    key = normalize(key)
    delete(key) if expired?(key)
  end

  super
end