Sha256: 31703e5731577870f8d62e8dfd53e13b7cfbefc9d76c122224195c819567f02b
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
module RedisFile # Represents a normal hash with some additional expiration information # associated with each key class ExpiringHash < Hash attr_reader :expires def initialize(*) super @expires = {} end def [](key) key = normalize key delete(key) if expired?(key) super end def []=(key, val) key = normalize key expire(key) super end def delete(key) key = normalize key expire(key) super end def expire(key) key = normalize key expires.delete(key) end def expired?(key) key = normalize key expires.include?(key) && expires[key] < Time.now end def key?(key) key = normalize key delete(key) if expired?(key) super end def values_at(*keys) keys.each do |key| key = normalize(key) delete(key) if expired?(key) end super end def keys super.select do |key| key = normalize(key) if expired?(key) delete(key) false else true end end end def normalize key key.to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redis-file-0.4.2 | lib/redis-file/expiring_hash.rb |