Sha256: 29a349bb3edb6f6809c6f79dcf5f05e4aef34eb4abdcc0224b1107120d342294
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
class Redis class Store < self module Namespace def set(key, val, options = nil) namespace(key) { |key| super(key, val, options) } end def setnx(key, val, options = nil) namespace(key) { |key| super(key, val, options) } end def get(key, options = nil) namespace(key) { |key| super(key, options) } end def exists(key) namespace(key) { |key| super(key) } end def incrby(key, increment) namespace(key) { |key| super(key, increment) } end def decrby(key, increment) namespace(key) { |key| super(key, increment) } end def keys(pattern = "*") namespace(pattern) { |pattern| super(pattern).map{|key| strip_namespace(key) } } end def del(*keys) super *keys.map {|key| interpolate(key) } end def mget(*keys) super *keys.map {|key| interpolate(key) } end def to_s "#{super} with namespace #{@namespace}" end def flushdb del *keys end private def namespace(key) yield interpolate(key) end def interpolate(key) key.match(namespace_regexp) ? key : "#{@namespace}:#{key}" end def strip_namespace(key) key.gsub namespace_regexp, "" end def namespace_regexp @namespace_regexp ||= %r{^#{@namespace}\:} end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
redis-store-1.1.2 | lib/redis/store/namespace.rb |