module Redis::Store::Namespace

Public Instance Methods

decrby(key, increment) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 32
def decrby(key, increment)
  namespace(key) { |key| super(key, increment) }
end
del(*keys) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 40
def del(*keys)
  super *keys.map {|key| interpolate(key) } if keys.any?
end
exists(key) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 24
def exists(key)
  namespace(key) { |key| super(key) }
end
expire(key, ttl) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 56
def expire(key, ttl)
   namespace(key) { |key| super(key, ttl) }
end
flushdb() click to toggle source
# File lib/redis/store/namespace.rb, line 68
def flushdb
  del *keys
end
get(key, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 20
def get(key, options = nil)
  namespace(key) { |key| super(key, options) }
end
incrby(key, increment) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 28
def incrby(key, increment)
  namespace(key) { |key| super(key, increment) }
end
keys(pattern = "*") click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 36
def keys(pattern = "*")
  namespace(pattern) { |pattern| super(pattern).map{|key| strip_namespace(key) } }
end
mget(*keys) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 44
def mget(*keys)
  options = keys.pop if keys.last.is_a? Hash
  if keys.any?
    # Marshalling gets extended before Namespace does, so we need to pass options further
    if singleton_class.ancestors.include? Marshalling
      super *keys.map {|key| interpolate(key) }, options
    else
      super *keys.map {|key| interpolate(key) }
    end
  end
end
set(key, val, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 4
def set(key, val, options = nil)
  namespace(key) { |key| super(key, val, options) }
end
setex(key, ttl, val, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 8
def setex(key, ttl, val, options = nil)
  namespace(key) { |key| super(key, ttl, val, options) }
end
setnx(key, val, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 12
def setnx(key, val, options = nil)
  namespace(key) { |key| super(key, val, options) }
end
to_s() click to toggle source
# File lib/redis/store/namespace.rb, line 64
def to_s
  "#{super} with namespace #{namespace_str}"
end
ttl(key, options = nil) click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 16
def ttl(key, options = nil)
  namespace(key) { |key| super(key) }
end

Private Instance Methods

interpolate(key) click to toggle source
# File lib/redis/store/namespace.rb, line 81
def interpolate(key)
  key.match(namespace_regexp) ? key : "#{namespace_str}:#{key}"
end
namespace(key) { |interpolate(key)| ... } click to toggle source
# File lib/redis/store/namespace.rb, line 73
def namespace(key)
  yield interpolate(key)
end
namespace_regexp() click to toggle source
# File lib/redis/store/namespace.rb, line 89
def namespace_regexp
  @namespace_regexps ||= {}
  @namespace_regexps[namespace_str] ||= %r{^#{namespace_str}\:}
end
namespace_str() click to toggle source
# File lib/redis/store/namespace.rb, line 77
def namespace_str
  @namespace.is_a?(Proc) ? @namespace.call : @namespace
end
strip_namespace(key) click to toggle source
# File lib/redis/store/namespace.rb, line 85
def strip_namespace(key)
  key.gsub namespace_regexp, ""
end