Module: Redis::Store::Namespace
- Defined in:
- lib/redis/store/namespace.rb
Constant Summary collapse
- FLUSHDB_BATCH_SIZE =
1000
Instance Method Summary collapse
- #decrby(key, increment) ⇒ Object
- #del(*keys) ⇒ Object
- #exists(key) ⇒ Object
- #expire(key, ttl) ⇒ Object
- #flushdb ⇒ Object
- #get(key, options = nil) ⇒ Object
- #hdel(key, *fields) ⇒ Object
- #hgetall(key) ⇒ Object
- #hlen(key) ⇒ Object
- #hscan(key, cursor, options = {}) ⇒ Object
- #hset(key, field, val) ⇒ Object
- #hsetnx(key, field, val) ⇒ Object
- #incrby(key, increment) ⇒ Object
- #keys(pattern = "*") ⇒ Object
- #mget(*keys, &blk) ⇒ Object
- #scan(cursor, options = {}) ⇒ Object
- #set(key, val, options = nil) ⇒ Object
- #setex(key, ttl, val, options = nil) ⇒ Object
- #setnx(key, val, options = nil) ⇒ Object
- #to_s ⇒ Object
- #ttl(key, options = nil) ⇒ Object
- #unlink(*keys) ⇒ Object
- #watch(*keys) ⇒ Object
- #with_namespace(ns) ⇒ Object
- #zadd(key, increment, member) ⇒ Object
- #zincrby(key, increment, member) ⇒ Object
- #zrem(key, member) ⇒ Object
- #zscore(key, member) ⇒ Object
Instance Method Details
#decrby(key, increment) ⇒ Object
34 35 36 |
# File 'lib/redis/store/namespace.rb', line 34 def decrby(key, increment) namespace(key) { |k| super(k, increment) } end |
#del(*keys) ⇒ Object
53 54 55 |
# File 'lib/redis/store/namespace.rb', line 53 def del(*keys) super(*keys.map { |key| interpolate(key) }) if keys.any? end |
#exists(key) ⇒ Object
26 27 28 |
# File 'lib/redis/store/namespace.rb', line 26 def exists(key) namespace(key) { |k| super(k) } end |
#expire(key, ttl) ⇒ Object
89 90 91 |
# File 'lib/redis/store/namespace.rb', line 89 def expire(key, ttl) namespace(key) { |k| super(k, ttl) } end |
#flushdb ⇒ Object
129 130 131 132 |
# File 'lib/redis/store/namespace.rb', line 129 def flushdb return super unless namespace_str keys.each_slice(FLUSHDB_BATCH_SIZE) { |key_slice| del(*key_slice) } end |
#get(key, options = nil) ⇒ Object
22 23 24 |
# File 'lib/redis/store/namespace.rb', line 22 def get(key, = nil) namespace(key) { |k| super(k, ) } end |
#hdel(key, *fields) ⇒ Object
97 98 99 |
# File 'lib/redis/store/namespace.rb', line 97 def hdel(key, *fields) namespace(key) { |k| super(k, fields) } end |
#hgetall(key) ⇒ Object
77 78 79 |
# File 'lib/redis/store/namespace.rb', line 77 def hgetall(key) namespace(key) { |k| super(k) } end |
#hlen(key) ⇒ Object
101 102 103 |
# File 'lib/redis/store/namespace.rb', line 101 def hlen(key) namespace(key) { |k| super(k) } end |
#hscan(key, cursor, options = {}) ⇒ Object
93 94 95 |
# File 'lib/redis/store/namespace.rb', line 93 def hscan(key, cursor, = {}) namespace(key) { |k| super(k, cursor, ) } end |
#hset(key, field, val) ⇒ Object
85 86 87 |
# File 'lib/redis/store/namespace.rb', line 85 def hset(key, field, val) namespace(key) { |k| super(k, field, val) } end |
#hsetnx(key, field, val) ⇒ Object
81 82 83 |
# File 'lib/redis/store/namespace.rb', line 81 def hsetnx(key, field, val) namespace(key) { |k| super(k, field, val) } end |
#incrby(key, increment) ⇒ Object
30 31 32 |
# File 'lib/redis/store/namespace.rb', line 30 def incrby(key, increment) namespace(key) { |k| super(k, increment) } end |
#keys(pattern = "*") ⇒ Object
38 39 40 |
# 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) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/redis/store/namespace.rb', line 65 def mget(*keys, &blk) = (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) }, , &blk) else super(*keys.map { |key| interpolate(key) }, &blk) end end end |
#scan(cursor, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/redis/store/namespace.rb', line 42 def scan(cursor, = {}) if [:match] namespace([:match]) do |pattern| cursor, keys = super(cursor, .merge(match: pattern)) [ cursor, keys.map{|key| strip_namespace(key) } ] end else super(cursor, ) end end |
#set(key, val, options = nil) ⇒ Object
6 7 8 |
# File 'lib/redis/store/namespace.rb', line 6 def set(key, val, = nil) namespace(key) { |k| super(k, val, ) } end |
#setex(key, ttl, val, options = nil) ⇒ Object
10 11 12 |
# File 'lib/redis/store/namespace.rb', line 10 def setex(key, ttl, val, = nil) namespace(key) { |k| super(k, ttl, val, ) } end |
#setnx(key, val, options = nil) ⇒ Object
14 15 16 |
# File 'lib/redis/store/namespace.rb', line 14 def setnx(key, val, = nil) namespace(key) { |k| super(k, val, ) } end |
#to_s ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/redis/store/namespace.rb', line 121 def to_s if namespace_str "#{super} with namespace #{namespace_str}" else super end end |
#ttl(key, options = nil) ⇒ Object
18 19 20 |
# File 'lib/redis/store/namespace.rb', line 18 def ttl(key, = nil) namespace(key) { |k| super(k) } end |
#unlink(*keys) ⇒ Object
57 58 59 |
# File 'lib/redis/store/namespace.rb', line 57 def unlink(*keys) super(*keys.map { |key| interpolate(key) }) if keys.any? end |
#watch(*keys) ⇒ Object
61 62 63 |
# File 'lib/redis/store/namespace.rb', line 61 def watch(*keys) super(*keys.map { |key| interpolate(key) }) if keys.any? end |
#with_namespace(ns) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/redis/store/namespace.rb', line 134 def with_namespace(ns) old_ns = @namespace @namespace = ns yield self ensure @namespace = old_ns end |
#zadd(key, increment, member) ⇒ Object
113 114 115 |
# File 'lib/redis/store/namespace.rb', line 113 def zadd(key, increment, member) namespace(key) { |k| super(k, increment, member) } end |
#zincrby(key, increment, member) ⇒ Object
105 106 107 |
# File 'lib/redis/store/namespace.rb', line 105 def zincrby(key, increment, member) namespace(key) { |k| super(k, increment, member) } end |
#zrem(key, member) ⇒ Object
117 118 119 |
# File 'lib/redis/store/namespace.rb', line 117 def zrem(key, member) namespace(key) { |k| super(k, member) } end |
#zscore(key, member) ⇒ Object
109 110 111 |
# File 'lib/redis/store/namespace.rb', line 109 def zscore(key, member) namespace(key) { |k| super(k, member) } end |