Module: Redis::Store::Namespace

Defined in:
lib/redis/store/namespace.rb

Constant Summary collapse

FLUSHDB_BATCH_SIZE =
1000

Instance Method Summary collapse

Instance Method Details

#decrby(key, increment) ⇒ Object



38
39
40
# File 'lib/redis/store/namespace.rb', line 38

def decrby(key, increment)
  namespace(key) { |k| super(k, increment) }
end

#del(*keys) ⇒ Object



57
58
59
# File 'lib/redis/store/namespace.rb', line 57

def del(*keys)
  super(*keys.map { |key| interpolate(key) }) if keys.any?
end

#exists(*keys) ⇒ Object



26
27
28
# File 'lib/redis/store/namespace.rb', line 26

def exists(*keys)
  super(*keys.map { |key| interpolate(key) })
end

#exists?(*keys) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/redis/store/namespace.rb', line 30

def exists?(*keys)
  super(*keys.map { |key| interpolate(key) })
end

#expire(key, ttl) ⇒ Object



81
82
83
# File 'lib/redis/store/namespace.rb', line 81

def expire(key, ttl)
  namespace(key) { |k| super(k, ttl) }
end

#flushdbObject



173
174
175
176
# File 'lib/redis/store/namespace.rb', line 173

def flushdb
  return super unless namespace_str
  keys.each_slice(FLUSHDB_BATCH_SIZE) { |key_slice| del(*key_slice) }
end

#get(key, *args) ⇒ Object



22
23
24
# File 'lib/redis/store/namespace.rb', line 22

def get(key, *args)
  namespace(key) { |k| super(k, *args) }
end

#hdel(key, *fields) ⇒ Object



85
86
87
# File 'lib/redis/store/namespace.rb', line 85

def hdel(key, *fields)
  namespace(key) { |k| super(k, *fields) }
end

#hexists(key, field) ⇒ Object



97
98
99
# File 'lib/redis/store/namespace.rb', line 97

def hexists(key, field)
  namespace(key) { |k| super(k, field) }
end

#hget(key, field) ⇒ Object



89
90
91
# File 'lib/redis/store/namespace.rb', line 89

def hget(key, field)
  namespace(key) { |k| super(k, field) }
end

#hgetall(key) ⇒ Object



93
94
95
# File 'lib/redis/store/namespace.rb', line 93

def hgetall(key)
  namespace(key) { |k| super(k) }
end

#hincrby(key, field, increment) ⇒ Object



101
102
103
# File 'lib/redis/store/namespace.rb', line 101

def hincrby(key, field, increment)
  namespace(key) { |k| super(k, field, increment) }
end

#hincrbyfloat(key, field, increment) ⇒ Object



105
106
107
# File 'lib/redis/store/namespace.rb', line 105

def hincrbyfloat(key, field, increment)
  namespace(key) { |k| super(k, field, increment) }
end

#hkeys(key) ⇒ Object



109
110
111
# File 'lib/redis/store/namespace.rb', line 109

def hkeys(key)
  namespace(key) { |k| super(k) }
end

#hlen(key) ⇒ Object



113
114
115
# File 'lib/redis/store/namespace.rb', line 113

def hlen(key)
  namespace(key) { |k| super(k) }
end

#hmget(key, *fields, &blk) ⇒ Object



117
118
119
# File 'lib/redis/store/namespace.rb', line 117

def hmget(key, *fields, &blk)
  namespace(key) { |k| super(k, *fields, &blk) }
end

#hmset(key, *attrs) ⇒ Object



121
122
123
# File 'lib/redis/store/namespace.rb', line 121

def hmset(key, *attrs)
  namespace(key) { |k| super(k, *attrs) }
end

#hscan(key, *args) ⇒ Object



137
138
139
# File 'lib/redis/store/namespace.rb', line 137

def hscan(key, *args)
  namespace(key) { |k| super(k, *args) }
end

#hscan_each(key, *args) ⇒ Object



141
142
143
# File 'lib/redis/store/namespace.rb', line 141

def hscan_each(key, *args)
  namespace(key) { |k| super(k, *args) }
end

#hset(key, *args) ⇒ Object



125
126
127
# File 'lib/redis/store/namespace.rb', line 125

def hset(key, *args)
  namespace(key) { |k| super(k, *args) }
end

#hsetnx(key, field, val) ⇒ Object



129
130
131
# File 'lib/redis/store/namespace.rb', line 129

def hsetnx(key, field, val)
  namespace(key) { |k| super(k, field, val) }
end

#hvals(key) ⇒ Object



133
134
135
# File 'lib/redis/store/namespace.rb', line 133

def hvals(key)
  namespace(key) { |k| super(k) }
end

#incrby(key, increment) ⇒ Object



34
35
36
# File 'lib/redis/store/namespace.rb', line 34

def incrby(key, increment)
  namespace(key) { |k| super(k, increment) }
end

#keys(pattern = "*") ⇒ Object



42
43
44
# File 'lib/redis/store/namespace.rb', line 42

def keys(pattern = "*")
  namespace(pattern) { |p| super(p).map { |key| strip_namespace(key) } }
end

#mget(*keys, &blk) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/redis/store/namespace.rb', line 69

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

#scan(cursor, match: nil, **kwargs) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/redis/store/namespace.rb', line 46

def scan(cursor, match: nil, **kwargs)
  if match
    namespace(match) do |pattern|
      cursor, keys = super(cursor, match: pattern, **kwargs)
      [ cursor, keys.map { |key| strip_namespace(key) } ]
    end
  else
    super(cursor, **kwargs)
  end
end

#set(key, *args) ⇒ Object



6
7
8
# File 'lib/redis/store/namespace.rb', line 6

def set(key, *args)
  namespace(key) { |k| super(k, *args) }
end

#setex(key, *args) ⇒ Object



10
11
12
# File 'lib/redis/store/namespace.rb', line 10

def setex(key, *args)
  namespace(key) { |k| super(k, *args) }
end

#setnx(key, *args) ⇒ Object



14
15
16
# File 'lib/redis/store/namespace.rb', line 14

def setnx(key, *args)
  namespace(key) { |k| super(k, *args) }
end

#to_sObject



165
166
167
168
169
170
171
# File 'lib/redis/store/namespace.rb', line 165

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, options = nil)
  namespace(key) { |k| super(k) }
end


61
62
63
# File 'lib/redis/store/namespace.rb', line 61

def unlink(*keys)
  super(*keys.map { |key| interpolate(key) }) if keys.any?
end

#watch(*keys) ⇒ Object



65
66
67
# File 'lib/redis/store/namespace.rb', line 65

def watch(*keys)
  super(*keys.map { |key| interpolate(key) }) if keys.any?
end

#with_namespace(ns) ⇒ Object



178
179
180
181
182
183
184
# File 'lib/redis/store/namespace.rb', line 178

def with_namespace(ns)
  old_ns = @namespace
  @namespace = ns
  yield self
ensure
  @namespace = old_ns
end

#zadd(key, *args) ⇒ Object



153
154
155
# File 'lib/redis/store/namespace.rb', line 153

def zadd(key, *args)
  namespace(key) { |k| super(k, *args) }
end

#zincrby(key, increment, member) ⇒ Object



145
146
147
# File 'lib/redis/store/namespace.rb', line 145

def zincrby(key, increment, member)
  namespace(key) { |k| super(k, increment, member) }
end

#zrem(key, member) ⇒ Object



157
158
159
# File 'lib/redis/store/namespace.rb', line 157

def zrem(key, member)
  namespace(key) { |k| super(k, member) }
end

#zscore(key, member) ⇒ Object



149
150
151
# File 'lib/redis/store/namespace.rb', line 149

def zscore(key, member)
  namespace(key) { |k| super(k, member) }
end