module Redis::Store::Namespace
Constants
- FLUSHDB_BATCH_SIZE
Public Instance Methods
decrby(key, increment)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 34 def decrby(key, increment) namespace(key) { |k| super(k, increment) } end
del(*keys)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 42 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 26 def exists(key) namespace(key) { |k| super(k) } end
expire(key, ttl)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 62 def expire(key, ttl) namespace(key) { |k| super(k, ttl) } end
flushdb()
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 74 def flushdb return super unless namespace_str keys.each_slice(FLUSHDB_BATCH_SIZE) { |key_slice| del(*key_slice) } end
get(key, options = nil)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 22 def get(key, options = nil) namespace(key) { |k| super(k, options) } end
incrby(key, increment)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 30 def incrby(key, increment) namespace(key) { |k| super(k, increment) } end
keys(pattern = "*")
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 38 def keys(pattern = "*") namespace(pattern) { |p| super(p).map{|key| strip_namespace(key) } } end
mget(*keys, &blk)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 50 def mget(*keys, &blk) options = (keys.pop if keys.last.is_a? Hash) || {} if keys.any? # Serialization gets extended before Namespace does, so we need to pass options further if singleton_class.ancestors.include? Serialization super(*keys.map {|key| interpolate(key) }, options, &blk) else super(*keys.map {|key| interpolate(key) }, &blk) end end end
set(key, val, options = nil)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 6 def set(key, val, options = nil) namespace(key) { |k| super(k, val, options) } end
setex(key, ttl, val, options = nil)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 10 def setex(key, ttl, val, options = nil) namespace(key) { |k| super(k, ttl, val, options) } end
setnx(key, val, options = nil)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 14 def setnx(key, val, options = nil) namespace(key) { |k| super(k, val, options) } end
to_s()
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 66 def to_s if namespace_str "#{super} with namespace #{namespace_str}" else super end end
ttl(key, options = nil)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 18 def ttl(key, options = nil) namespace(key) { |k| super(k) } end
watch(*keys)
click to toggle source
Calls superclass method
# File lib/redis/store/namespace.rb, line 46 def watch(*keys) super(*keys.map {|key| interpolate(key) }) if keys.any? end
with_namespace(ns) { |self| ... }
click to toggle source
# File lib/redis/store/namespace.rb, line 79 def with_namespace(ns) old_ns = @namespace @namespace = ns yield self ensure @namespace = old_ns end
Private Instance Methods
interpolate(key)
click to toggle source
# File lib/redis/store/namespace.rb, line 96 def interpolate(key) return key unless namespace_str key.match(namespace_regexp) ? key : "#{namespace_str}:#{key}" end
namespace(key) { |interpolate(key)| ... }
click to toggle source
# File lib/redis/store/namespace.rb, line 88 def namespace(key) yield interpolate(key) end
namespace_regexp()
click to toggle source
# File lib/redis/store/namespace.rb, line 106 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 92 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 101 def strip_namespace(key) return key unless namespace_str key.gsub namespace_regexp, "" end