redis-namespace 1.8.2 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/redis/namespace/version.rb +1 -1
- data/lib/redis/namespace.rb +67 -16
- data/spec/deprecation_spec.rb +1 -1
- data/spec/redis_spec.rb +146 -9
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c4fe7070f484a694ce41f97a0297e03d92cfa67746903d9fb74fa8439410494
|
4
|
+
data.tar.gz: 0cbfe04c2ca7b2d42ee603f0d67ba21c13cb938832cc99f89a2323842bb828a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec085b7e9fba5241cb2e2ad4ccf22d4282001a0ee37731e408a2135ea5e5439747441046cc6c48a2a372afe99f2fb6a67401867a20c8605e41206954eca72078
|
7
|
+
data.tar.gz: 0eff5c268bba88cb8bd5e0ab8115a404fed3180e82ebc4297ab8675da6c73e13b3bb943e77ec0392de4460683488589bbc227d95515aa5dc70cdb4236b58801d
|
data/README.md
CHANGED
@@ -33,6 +33,13 @@ redis_connection.get('ns:foo')
|
|
33
33
|
# => nil
|
34
34
|
```
|
35
35
|
|
36
|
+
Redis::Namespace also supports `Proc` as a namespace and will take the result string as namespace at runtime.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
redis_connection = Redis.new
|
40
|
+
namespaced_redis = Redis::Namespace.new(Proc.new { Tenant.current_tenant }, redis: redis_connection)
|
41
|
+
```
|
42
|
+
|
36
43
|
Installation
|
37
44
|
============
|
38
45
|
|
data/lib/redis/namespace.rb
CHANGED
@@ -75,6 +75,7 @@ class Redis
|
|
75
75
|
"eval" => [ :eval_style ],
|
76
76
|
"evalsha" => [ :eval_style ],
|
77
77
|
"get" => [ :first ],
|
78
|
+
"getex" => [ :first ],
|
78
79
|
"getbit" => [ :first ],
|
79
80
|
"getrange" => [ :first ],
|
80
81
|
"getset" => [ :first ],
|
@@ -137,6 +138,7 @@ class Redis
|
|
137
138
|
"rpush" => [ :first ],
|
138
139
|
"rpushx" => [ :first ],
|
139
140
|
"sadd" => [ :first ],
|
141
|
+
"sadd?" => [ :first ],
|
140
142
|
"scard" => [ :first ],
|
141
143
|
"scan" => [ :scan_style, :second ],
|
142
144
|
"scan_each" => [ :scan_style, :all ],
|
@@ -151,6 +153,7 @@ class Redis
|
|
151
153
|
"sinterstore" => [ :all ],
|
152
154
|
"sismember" => [ :first ],
|
153
155
|
"smembers" => [ :first ],
|
156
|
+
"smismember" => [ :first ],
|
154
157
|
"smove" => [ :exclude_last ],
|
155
158
|
"sort" => [ :sort ],
|
156
159
|
"spop" => [ :first ],
|
@@ -200,6 +203,7 @@ class Redis
|
|
200
203
|
HELPER_COMMANDS = {
|
201
204
|
"auth" => [],
|
202
205
|
"disconnect!" => [],
|
206
|
+
"close" => [],
|
203
207
|
"echo" => [],
|
204
208
|
"ping" => [],
|
205
209
|
"time" => [],
|
@@ -236,13 +240,20 @@ class Redis
|
|
236
240
|
# Support 1.8.7 by providing a namespaced reference to Enumerable::Enumerator
|
237
241
|
Enumerator = Enumerable::Enumerator unless defined?(::Enumerator)
|
238
242
|
|
243
|
+
# This is used by the Redis gem to determine whether or not to display that deprecation message.
|
244
|
+
@sadd_returns_boolean = true
|
245
|
+
|
246
|
+
class << self
|
247
|
+
attr_accessor :sadd_returns_boolean
|
248
|
+
end
|
249
|
+
|
239
250
|
attr_writer :namespace
|
240
251
|
attr_reader :redis
|
241
252
|
attr_accessor :warning
|
242
253
|
|
243
254
|
def initialize(namespace, options = {})
|
244
255
|
@namespace = namespace
|
245
|
-
@redis = options[:redis] || Redis.
|
256
|
+
@redis = options[:redis] || Redis.new
|
246
257
|
@warning = !!options.fetch(:warning) do
|
247
258
|
!ENV['REDIS_NAMESPACE_QUIET']
|
248
259
|
end
|
@@ -261,7 +272,7 @@ class Redis
|
|
261
272
|
end
|
262
273
|
|
263
274
|
def client
|
264
|
-
warn("The client method is deprecated as of redis-rb 4.0.0, please use the new _client" +
|
275
|
+
warn("The client method is deprecated as of redis-rb 4.0.0, please use the new _client " +
|
265
276
|
"method instead. Support for the old method will be removed in redis-namespace 2.0.") if @has_new_client_method && deprecations?
|
266
277
|
_client
|
267
278
|
end
|
@@ -307,7 +318,7 @@ class Redis
|
|
307
318
|
:redis => @redis)
|
308
319
|
end
|
309
320
|
|
310
|
-
@namespace
|
321
|
+
@namespace.respond_to?(:call) ? @namespace.call : @namespace
|
311
322
|
end
|
312
323
|
|
313
324
|
def full_namespace
|
@@ -315,7 +326,7 @@ class Redis
|
|
315
326
|
end
|
316
327
|
|
317
328
|
def connection
|
318
|
-
@redis.connection.tap { |info| info[:namespace] =
|
329
|
+
@redis.connection.tap { |info| info[:namespace] = namespace }
|
319
330
|
end
|
320
331
|
|
321
332
|
def exec
|
@@ -327,6 +338,32 @@ class Redis
|
|
327
338
|
end
|
328
339
|
ruby2_keywords(:eval) if respond_to?(:ruby2_keywords, true)
|
329
340
|
|
341
|
+
# This operation can run for a very long time if the namespace contains lots of keys!
|
342
|
+
# It should be used in tests, or when the namespace is small enough
|
343
|
+
# and you are sure you know what you are doing.
|
344
|
+
def clear
|
345
|
+
if warning?
|
346
|
+
warn("This operation can run for a very long time if the namespace contains lots of keys! " +
|
347
|
+
"It should be used in tests, or when the namespace is small enough " +
|
348
|
+
"and you are sure you know what you are doing.")
|
349
|
+
end
|
350
|
+
|
351
|
+
batch_size = 1000
|
352
|
+
|
353
|
+
if supports_scan?
|
354
|
+
cursor = "0"
|
355
|
+
begin
|
356
|
+
cursor, keys = scan(cursor, count: batch_size)
|
357
|
+
del(*keys) unless keys.empty?
|
358
|
+
end until cursor == "0"
|
359
|
+
else
|
360
|
+
all_keys = keys("*")
|
361
|
+
all_keys.each_slice(batch_size) do |keys|
|
362
|
+
del(*keys)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
330
367
|
ADMINISTRATIVE_COMMANDS.keys.each do |command|
|
331
368
|
define_method(command) do |*args, &block|
|
332
369
|
raise NoMethodError if deprecations?
|
@@ -369,7 +406,8 @@ class Redis
|
|
369
406
|
"passthrough has been deprecated and will be removed in " +
|
370
407
|
"redis-namespace 2.0 (at #{call_site})")
|
371
408
|
end
|
372
|
-
|
409
|
+
|
410
|
+
wrapped_send(@redis, command, args, &block)
|
373
411
|
else
|
374
412
|
super
|
375
413
|
end
|
@@ -430,6 +468,7 @@ class Redis
|
|
430
468
|
args = add_namespace(args)
|
431
469
|
end
|
432
470
|
when :alternate
|
471
|
+
args = args.flatten
|
433
472
|
args.each_with_index { |a, i| args[i] = add_namespace(a) if i.even? }
|
434
473
|
when :sort
|
435
474
|
args[0] = add_namespace(args[0]) if args[0]
|
@@ -473,7 +512,7 @@ class Redis
|
|
473
512
|
end
|
474
513
|
|
475
514
|
# Dispatch the command to Redis and store the result.
|
476
|
-
result = @redis
|
515
|
+
result = wrapped_send(@redis, command, args, &block)
|
477
516
|
|
478
517
|
# Don't try to remove namespace from a Redis::Future, you can't.
|
479
518
|
return result if result.is_a?(Redis::Future)
|
@@ -510,6 +549,16 @@ class Redis
|
|
510
549
|
end
|
511
550
|
end
|
512
551
|
|
552
|
+
def wrapped_send(redis_client, command, args = [], &block)
|
553
|
+
if redis_client.class.name == "ConnectionPool"
|
554
|
+
redis_client.with do |pool_connection|
|
555
|
+
pool_connection.send(command, *args, &block)
|
556
|
+
end
|
557
|
+
else
|
558
|
+
redis_client.send(command, *args, &block)
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
513
562
|
# Avoid modifying the caller's (pass-by-reference) arguments.
|
514
563
|
def clone_args(arg)
|
515
564
|
if arg.is_a?(Array)
|
@@ -527,18 +576,15 @@ class Redis
|
|
527
576
|
|
528
577
|
def namespaced_block(command, &block)
|
529
578
|
if block.arity == 0
|
530
|
-
redis
|
579
|
+
wrapped_send(redis, command, &block)
|
531
580
|
else
|
532
|
-
|
533
|
-
|
534
|
-
copy.redis = r
|
535
|
-
yield copy
|
536
|
-
end
|
581
|
+
outer_block = proc { |r| copy = dup; copy.redis = r; yield copy }
|
582
|
+
wrapped_send(redis, command, &outer_block)
|
537
583
|
end
|
538
584
|
end
|
539
585
|
|
540
586
|
def add_namespace(key)
|
541
|
-
return key unless key &&
|
587
|
+
return key unless key && namespace
|
542
588
|
|
543
589
|
case key
|
544
590
|
when Array
|
@@ -547,12 +593,12 @@ class Redis
|
|
547
593
|
key.keys.each {|k| key[add_namespace(k)] = key.delete(k)}
|
548
594
|
key
|
549
595
|
else
|
550
|
-
"#{
|
596
|
+
"#{namespace}:#{key}"
|
551
597
|
end
|
552
598
|
end
|
553
599
|
|
554
600
|
def rem_namespace(key)
|
555
|
-
return key unless key &&
|
601
|
+
return key unless key && namespace
|
556
602
|
|
557
603
|
case key
|
558
604
|
when Array
|
@@ -564,7 +610,7 @@ class Redis
|
|
564
610
|
key.each { |k| yielder.yield rem_namespace(k) }
|
565
611
|
end
|
566
612
|
else
|
567
|
-
key.to_s.sub(/\A#{
|
613
|
+
key.to_s.sub(/\A#{namespace}:/, '')
|
568
614
|
end
|
569
615
|
end
|
570
616
|
|
@@ -579,5 +625,10 @@ class Redis
|
|
579
625
|
Enumerator.new(&block)
|
580
626
|
end
|
581
627
|
end
|
628
|
+
|
629
|
+
def supports_scan?
|
630
|
+
redis_version = @redis.info["redis_version"]
|
631
|
+
Gem::Version.new(redis_version) >= Gem::Version.new("2.8.0")
|
632
|
+
end
|
582
633
|
end
|
583
634
|
end
|
data/spec/deprecation_spec.rb
CHANGED
data/spec/redis_spec.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/spec_helper'
|
4
|
+
require 'connection_pool'
|
4
5
|
|
5
6
|
describe "redis" do
|
6
|
-
@redis_version = Gem::Version.new(Redis.
|
7
|
+
@redis_version = Gem::Version.new(Redis.new.info["redis_version"])
|
7
8
|
let(:redis_client) { @redis.respond_to?(:_client) ? @redis._client : @redis.client}
|
8
9
|
|
9
10
|
before(:each) do
|
@@ -41,6 +42,17 @@ describe "redis" do
|
|
41
42
|
expect(@namespaced.type('counter')).to eq('string')
|
42
43
|
end
|
43
44
|
|
45
|
+
it "should work with Proc namespaces" do
|
46
|
+
namespace = Proc.new { :dynamic_ns }
|
47
|
+
namespaced = Redis::Namespace.new(namespace, redis: @redis)
|
48
|
+
|
49
|
+
expect(namespaced.get('foo')).to eq(nil)
|
50
|
+
namespaced.set('foo', 'chris')
|
51
|
+
expect(namespaced.get('foo')).to eq('chris')
|
52
|
+
@redis.set('foo', 'bob')
|
53
|
+
expect(@redis.get('foo')).to eq('bob')
|
54
|
+
end
|
55
|
+
|
44
56
|
context 'when sending capital commands (issue 68)' do
|
45
57
|
it 'should be able to use a namespace' do
|
46
58
|
@namespaced.send('SET', 'fubar', 'quux')
|
@@ -95,6 +107,13 @@ describe "redis" do
|
|
95
107
|
expect(@namespaced.lrange('bar',0,-1)).to eq(['bar'])
|
96
108
|
end
|
97
109
|
|
110
|
+
it "should be able to use a namespace with getex" do
|
111
|
+
expect(@namespaced.set('mykey', 'Hello')).to eq('OK')
|
112
|
+
expect(@namespaced.getex('mykey', ex: 50)).to eq('Hello')
|
113
|
+
expect(@namespaced.get('mykey')).to eq('Hello')
|
114
|
+
expect(@namespaced.ttl('mykey')).to eq(50)
|
115
|
+
end
|
116
|
+
|
98
117
|
it 'should be able to use a namespace with getbit' do
|
99
118
|
@namespaced.set('foo','bar')
|
100
119
|
expect(@namespaced.getbit('foo',1)).to eq(1)
|
@@ -166,19 +185,44 @@ describe "redis" do
|
|
166
185
|
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil})
|
167
186
|
end
|
168
187
|
|
188
|
+
it "should utilize connection_pool while using a namespace with mget" do
|
189
|
+
memo = @namespaced
|
190
|
+
connection_pool = ConnectionPool.new(size: 2, timeout: 2) { Redis.new db: 15 }
|
191
|
+
@namespaced = Redis::Namespace.new(:ns, redis: connection_pool)
|
192
|
+
|
193
|
+
expect(connection_pool).to receive(:with).and_call_original do |arg|
|
194
|
+
expect(arg).to be(an_instance_of(Redis))
|
195
|
+
end.at_least(:once)
|
196
|
+
|
197
|
+
@namespaced.set('foo', 1000)
|
198
|
+
@namespaced.set('bar', 2000)
|
199
|
+
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
|
200
|
+
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({'foo'=>'1000', 'bar'=>'2000', 'baz' => nil})
|
201
|
+
@redis.get('foo').should eq('bar')
|
202
|
+
|
203
|
+
@namespaced = memo
|
204
|
+
end
|
205
|
+
|
169
206
|
it "should be able to use a namespace with mset" do
|
170
207
|
@namespaced.mset('foo', '1000', 'bar', '2000')
|
171
208
|
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
|
172
209
|
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
|
210
|
+
|
173
211
|
@namespaced.mapped_mset('foo' => '3000', 'bar' => '5000')
|
174
212
|
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000' })
|
175
213
|
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000', 'baz' => nil})
|
214
|
+
|
215
|
+
@namespaced.mset(['foo', '4000'], ['baz', '6000'])
|
216
|
+
expect(@namespaced.mapped_mget('foo', 'bar', 'baz')).to eq({ 'foo' => '4000', 'bar' => '5000', 'baz' => '6000' })
|
176
217
|
end
|
177
218
|
|
178
219
|
it "should be able to use a namespace with msetnx" do
|
179
220
|
@namespaced.msetnx('foo', '1000', 'bar', '2000')
|
180
221
|
expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
|
181
222
|
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
|
223
|
+
|
224
|
+
@namespaced.msetnx(['baz', '4000'])
|
225
|
+
expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => '4000'})
|
182
226
|
end
|
183
227
|
|
184
228
|
it "should be able to use a namespace with mapped_msetnx" do
|
@@ -314,6 +358,11 @@ describe "redis" do
|
|
314
358
|
expect(values).to match_array(['banana', 'eggplant'])
|
315
359
|
end
|
316
360
|
|
361
|
+
it "should add a new member" do
|
362
|
+
expect(@namespaced.sadd?('foo', 1)).to eq(true)
|
363
|
+
expect(@namespaced.sadd?('foo', 1)).to eq(false)
|
364
|
+
end
|
365
|
+
|
317
366
|
it "should add namespace to sort" do
|
318
367
|
@namespaced.sadd('foo', 1)
|
319
368
|
@namespaced.sadd('foo', 2)
|
@@ -351,6 +400,26 @@ describe "redis" do
|
|
351
400
|
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
352
401
|
end
|
353
402
|
|
403
|
+
it "should utilize connection_pool while adding namepsace to multi blocks" do
|
404
|
+
memo = @namespaced
|
405
|
+
connection_pool = ConnectionPool.new(size: 2, timeout: 2) { Redis.new db: 15 }
|
406
|
+
@namespaced = Redis::Namespace.new(:ns, redis: connection_pool)
|
407
|
+
|
408
|
+
expect(connection_pool).to receive(:with).and_call_original do |arg|
|
409
|
+
expect(arg).to be(an_instance_of(Redis))
|
410
|
+
end.at_least(:once)
|
411
|
+
|
412
|
+
@namespaced.mapped_hmset "foo", {"key" => "value"}
|
413
|
+
@namespaced.multi do |r|
|
414
|
+
r.del "foo"
|
415
|
+
r.mapped_hmset "foo", {"key1" => "value1"}
|
416
|
+
end
|
417
|
+
expect(@redis.get("foo")).to eq("bar")
|
418
|
+
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
419
|
+
|
420
|
+
@namespaced = memo
|
421
|
+
end
|
422
|
+
|
354
423
|
it "should pass through multi commands without block" do
|
355
424
|
@namespaced.mapped_hmset "foo", {"key" => "value"}
|
356
425
|
|
@@ -362,6 +431,28 @@ describe "redis" do
|
|
362
431
|
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
363
432
|
end
|
364
433
|
|
434
|
+
it "should utilize connection_pool while passing through multi commands without block" do
|
435
|
+
memo = @namespaced
|
436
|
+
connection_pool = ConnectionPool.new(size: 2, timeout: 2) { Redis.new db: 15 }
|
437
|
+
@namespaced = Redis::Namespace.new(:ns, redis: connection_pool)
|
438
|
+
|
439
|
+
expect(connection_pool).to receive(:with).and_call_original do |arg|
|
440
|
+
expect(arg).to be(an_instance_of(Redis))
|
441
|
+
end.at_least(:once)
|
442
|
+
|
443
|
+
@namespaced.mapped_hmset "foo", {"key" => "value"}
|
444
|
+
|
445
|
+
@namespaced.multi
|
446
|
+
@namespaced.del "foo"
|
447
|
+
@namespaced.mapped_hmset "foo", {"key1" => "value1"}
|
448
|
+
@namespaced.exec
|
449
|
+
|
450
|
+
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
451
|
+
expect(@redis.get("foo")).to eq("bar")
|
452
|
+
|
453
|
+
@namespaced = memo
|
454
|
+
end
|
455
|
+
|
365
456
|
it 'should return futures without attempting to remove namespaces' do
|
366
457
|
@namespaced.multi do
|
367
458
|
@future = @namespaced.keys('*')
|
@@ -378,6 +469,26 @@ describe "redis" do
|
|
378
469
|
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
379
470
|
end
|
380
471
|
|
472
|
+
it "should utilize connection_pool while adding namespace to pipelined blocks" do
|
473
|
+
memo = @namespaced
|
474
|
+
connection_pool = ConnectionPool.new(size: 2, timeout: 2) { Redis.new db: 15 }
|
475
|
+
@namespaced = Redis::Namespace.new(:ns, redis: connection_pool)
|
476
|
+
|
477
|
+
expect(connection_pool).to receive(:with).and_call_original do |arg|
|
478
|
+
expect(arg).to be(an_instance_of(Redis))
|
479
|
+
end.at_least(:once)
|
480
|
+
|
481
|
+
@namespaced.mapped_hmset "foo", {"key" => "value"}
|
482
|
+
@namespaced.pipelined do |r|
|
483
|
+
r.del "foo"
|
484
|
+
r.mapped_hmset "foo", {"key1" => "value1"}
|
485
|
+
end
|
486
|
+
expect(@namespaced.hgetall("foo")).to eq({"key1" => "value1"})
|
487
|
+
expect(@redis.get("foo")).to eq("bar")
|
488
|
+
|
489
|
+
@namespaced = memo
|
490
|
+
end
|
491
|
+
|
381
492
|
it "should returned response array from pipelined block" do
|
382
493
|
@namespaced.mset "foo", "bar", "key", "value"
|
383
494
|
result = @namespaced.pipelined do |r|
|
@@ -687,7 +798,7 @@ describe "redis" do
|
|
687
798
|
expect(result).to match_array(namespaced_keys)
|
688
799
|
end
|
689
800
|
end
|
690
|
-
end if Redis.
|
801
|
+
end if Redis.new.respond_to?(:scan)
|
691
802
|
|
692
803
|
context '#scan_each' do
|
693
804
|
context 'when :match supplied' do
|
@@ -720,7 +831,7 @@ describe "redis" do
|
|
720
831
|
end
|
721
832
|
end
|
722
833
|
end
|
723
|
-
end if Redis.
|
834
|
+
end if Redis.new.respond_to?(:scan_each)
|
724
835
|
end
|
725
836
|
|
726
837
|
context 'hash scan methods' do
|
@@ -748,7 +859,7 @@ describe "redis" do
|
|
748
859
|
expect(results).to match_array(@redis.hgetall('ns:hsh').to_a)
|
749
860
|
end
|
750
861
|
end
|
751
|
-
end if Redis.
|
862
|
+
end if Redis.new.respond_to?(:hscan)
|
752
863
|
|
753
864
|
context '#hscan_each' do
|
754
865
|
context 'when :match supplied' do
|
@@ -781,7 +892,7 @@ describe "redis" do
|
|
781
892
|
end
|
782
893
|
end
|
783
894
|
end
|
784
|
-
end if Redis.
|
895
|
+
end if Redis.new.respond_to?(:hscan_each)
|
785
896
|
end
|
786
897
|
|
787
898
|
context 'set scan methods' do
|
@@ -809,7 +920,7 @@ describe "redis" do
|
|
809
920
|
expect(results).to match_array(set)
|
810
921
|
end
|
811
922
|
end
|
812
|
-
end if Redis.
|
923
|
+
end if Redis.new.respond_to?(:sscan)
|
813
924
|
|
814
925
|
context '#sscan_each' do
|
815
926
|
context 'when :match supplied' do
|
@@ -842,7 +953,7 @@ describe "redis" do
|
|
842
953
|
end
|
843
954
|
end
|
844
955
|
end
|
845
|
-
end if Redis.
|
956
|
+
end if Redis.new.respond_to?(:sscan_each)
|
846
957
|
end
|
847
958
|
|
848
959
|
context 'zset scan methods' do
|
@@ -872,7 +983,7 @@ describe "redis" do
|
|
872
983
|
expect(results).to match_array(hash.to_a)
|
873
984
|
end
|
874
985
|
end
|
875
|
-
end if Redis.
|
986
|
+
end if Redis.new.respond_to?(:zscan)
|
876
987
|
|
877
988
|
context '#zscan_each' do
|
878
989
|
context 'when :match supplied' do
|
@@ -905,7 +1016,7 @@ describe "redis" do
|
|
905
1016
|
end
|
906
1017
|
end
|
907
1018
|
end
|
908
|
-
end if Redis.
|
1019
|
+
end if Redis.new.respond_to?(:zscan_each)
|
909
1020
|
end
|
910
1021
|
end
|
911
1022
|
end
|
@@ -942,4 +1053,30 @@ describe "redis" do
|
|
942
1053
|
expect(sub_sub_namespaced.full_namespace).to eql("ns:sub1:sub2")
|
943
1054
|
end
|
944
1055
|
end
|
1056
|
+
|
1057
|
+
describe :clear do
|
1058
|
+
it "warns with helpful output" do
|
1059
|
+
expect { @namespaced.clear }.to output(/can run for a very long time/).to_stderr
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
it "should delete all the keys" do
|
1063
|
+
@redis.set("foo", "bar")
|
1064
|
+
@namespaced.mset("foo1", "bar", "foo2", "bar")
|
1065
|
+
capture_stderr { @namespaced.clear }
|
1066
|
+
|
1067
|
+
expect(@redis.keys).to eq ["foo"]
|
1068
|
+
expect(@namespaced.keys).to be_empty
|
1069
|
+
end
|
1070
|
+
|
1071
|
+
it "should delete all the keys in older redis" do
|
1072
|
+
allow(@redis).to receive(:info).and_return({ "redis_version" => "2.7.0" })
|
1073
|
+
|
1074
|
+
@redis.set("foo", "bar")
|
1075
|
+
@namespaced.mset("foo1", "bar", "foo2", "bar")
|
1076
|
+
capture_stderr { @namespaced.clear }
|
1077
|
+
|
1078
|
+
expect(@redis.keys).to eq ["foo"]
|
1079
|
+
expect(@namespaced.keys).to be_empty
|
1080
|
+
end
|
1081
|
+
end
|
945
1082
|
end
|
metadata
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-namespace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
8
8
|
- Terence Lee
|
9
9
|
- Steve Klabnik
|
10
10
|
- Ryan Biesemeyer
|
11
|
+
- Mike Bianco
|
11
12
|
autorequire:
|
12
13
|
bindir: bin
|
13
14
|
cert_chain: []
|
14
|
-
date: 2022-
|
15
|
+
date: 2022-12-20 00:00:00.000000000 Z
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
18
|
name: redis
|
@@ -19,14 +20,14 @@ dependencies:
|
|
19
20
|
requirements:
|
20
21
|
- - ">="
|
21
22
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
23
|
+
version: '4'
|
23
24
|
type: :runtime
|
24
25
|
prerelease: false
|
25
26
|
version_requirements: !ruby/object:Gem::Requirement
|
26
27
|
requirements:
|
27
28
|
- - ">="
|
28
29
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
+
version: '4'
|
30
31
|
- !ruby/object:Gem::Dependency
|
31
32
|
name: rake
|
32
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,6 +70,20 @@ dependencies:
|
|
69
70
|
- - ">="
|
70
71
|
- !ruby/object:Gem::Version
|
71
72
|
version: '0'
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: connection_pool
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
type: :development
|
81
|
+
prerelease: false
|
82
|
+
version_requirements: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
72
87
|
description: |
|
73
88
|
Adds a Redis::Namespace class which can be used to namespace calls
|
74
89
|
to Redis. This is useful when using a single instance of Redis with
|
@@ -78,6 +93,7 @@ email:
|
|
78
93
|
- hone02@gmail.com
|
79
94
|
- steve@steveklabnik.com
|
80
95
|
- me@yaauie.com
|
96
|
+
- mike@mikebian.co
|
81
97
|
executables: []
|
82
98
|
extensions: []
|
83
99
|
extra_rdoc_files: []
|
@@ -97,8 +113,8 @@ licenses:
|
|
97
113
|
metadata:
|
98
114
|
bug_tracker_uri: https://github.com/resque/redis-namespace/issues
|
99
115
|
changelog_uri: https://github.com/resque/redis-namespace/blob/master/CHANGELOG.md
|
100
|
-
documentation_uri: https://www.rubydoc.info/gems/redis-namespace/1.
|
101
|
-
|
116
|
+
documentation_uri: https://www.rubydoc.info/gems/redis-namespace/1.10.0
|
117
|
+
rubygems_mfa_required: 'true'
|
102
118
|
post_install_message:
|
103
119
|
rdoc_options: []
|
104
120
|
require_paths:
|
@@ -114,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
130
|
- !ruby/object:Gem::Version
|
115
131
|
version: '0'
|
116
132
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.3.15
|
118
134
|
signing_key:
|
119
135
|
specification_version: 4
|
120
136
|
summary: Namespaces Redis commands.
|