Sha256: 7aad925fdc5b8c1095c08a2a8fa392545e4d90327ef958e1394c725efdef4b78
Contents?: true
Size: 1.69 KB
Versions: 3
Compression:
Stored size: 1.69 KB
Contents
module FakeRedis class Redis module KeysMethods def del(*keys) old_count = @data.keys.size keys.flatten.each do |key| @data.delete(key) @expires.delete(key) end deleted_count = old_count - @data.keys.size end def exists(key) @data.key?(key) end def expire(key, ttl) return unless @data[key] @expires[key] = ttl true end def expireat(key, timestamp) @expires[key] = (Time.at(timestamp) - Time.now).to_i true end def keys(pattern = "*") regexp = Regexp.new(pattern.split("*").map { |r| Regexp.escape(r) }.join(".*")) @data.keys.select { |key| key =~ regexp } end def persist(key) @expires[key] = -1 end def randomkey @data.keys[rand(dbsize)] end def rename(key, new_key) return unless @data[key] @data[new_key] = @data[key] @expires[new_key] = @expires[key] @data.delete(key) @expires.delete(key) end def renamenx(key, new_key) rename(key, new_key) unless exists(new_key) end def sort(key) # TODO: Impleent end def ttl(key) @expires[key] end def type(key) case value = @data[key] when nil then "none" when String then "string" when Hash then "hash" when Array then "list" when Set then "set" end end protected def expired?(key) return false if @expires[key] == -1 return true if @expires[key] && @expires[key] < Time.now end end include KeysMethods end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fakeredis-0.1.4 | lib/fakeredis/keys.rb |
fakeredis-0.1.3 | lib/fakeredis/keys.rb |
fakeredis-0.1.2 | lib/fakeredis/keys.rb |