redis-namespace 1.8.2 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0541ad1ce3251b5dc3c035e47aa0690d334d32b9c5b29e335604570cb5847dac
4
- data.tar.gz: '0877ceadbd1afa44a38fd1b7bb7af4b0e9e87a3426f688c891c847853588f65a'
3
+ metadata.gz: 88bd88ddb249a9424c8bcc002b84f097a96b4de6450944bc66096e6524115431
4
+ data.tar.gz: 1b9b4d59744b77a65ec523a77ea438de1f0923494a838c94a8c312893dce1fa6
5
5
  SHA512:
6
- metadata.gz: 9c8cd0be52f98f4fe16b551ac261faba1db4da269a07ac9c85e4a8a4b20347c0a4646036bc5fb64cab3d5863d88b308f15ea96996fd19bfad8bd85980ccf5081
7
- data.tar.gz: 1d6e8e911c9bf887ff00cead444978ecfcccd6f2b04c56549fd28542864e7971ca9f4e5510d2e7473efb91bac50be8ac7d7cd9555fea5ca0da63d8b374d3e793
6
+ metadata.gz: 2007d2f5396aec757c50d77de437dc01630b10de02eaeb852f7858233729476582036cf8214ba6e893f3e26b574c22169530a44bf9fb24c39fa2f2d5958e7ee5
7
+ data.tar.gz: af47dc4b2ce8357f8751c99ed71d05dc213a75a8092a3d54f016cef36b327967445b915bfaed32565639b0b2c16dbd02ef0026fbabcbf07c8965d3bb42b04f16
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Redis
4
4
  class Namespace
5
- VERSION = '1.8.2'
5
+ VERSION = '1.9.0'
6
6
  end
7
7
  end
@@ -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 ],
@@ -151,6 +152,7 @@ class Redis
151
152
  "sinterstore" => [ :all ],
152
153
  "sismember" => [ :first ],
153
154
  "smembers" => [ :first ],
155
+ "smismember" => [ :first ],
154
156
  "smove" => [ :exclude_last ],
155
157
  "sort" => [ :sort ],
156
158
  "spop" => [ :first ],
@@ -242,7 +244,7 @@ class Redis
242
244
 
243
245
  def initialize(namespace, options = {})
244
246
  @namespace = namespace
245
- @redis = options[:redis] || Redis.current
247
+ @redis = options[:redis] || Redis.new
246
248
  @warning = !!options.fetch(:warning) do
247
249
  !ENV['REDIS_NAMESPACE_QUIET']
248
250
  end
@@ -261,7 +263,7 @@ class Redis
261
263
  end
262
264
 
263
265
  def client
264
- warn("The client method is deprecated as of redis-rb 4.0.0, please use the new _client" +
266
+ warn("The client method is deprecated as of redis-rb 4.0.0, please use the new _client " +
265
267
  "method instead. Support for the old method will be removed in redis-namespace 2.0.") if @has_new_client_method && deprecations?
266
268
  _client
267
269
  end
@@ -307,7 +309,7 @@ class Redis
307
309
  :redis => @redis)
308
310
  end
309
311
 
310
- @namespace
312
+ @namespace.respond_to?(:call) ? @namespace.call : @namespace
311
313
  end
312
314
 
313
315
  def full_namespace
@@ -315,7 +317,7 @@ class Redis
315
317
  end
316
318
 
317
319
  def connection
318
- @redis.connection.tap { |info| info[:namespace] = @namespace }
320
+ @redis.connection.tap { |info| info[:namespace] = namespace }
319
321
  end
320
322
 
321
323
  def exec
@@ -430,6 +432,7 @@ class Redis
430
432
  args = add_namespace(args)
431
433
  end
432
434
  when :alternate
435
+ args = args.flatten
433
436
  args.each_with_index { |a, i| args[i] = add_namespace(a) if i.even? }
434
437
  when :sort
435
438
  args[0] = add_namespace(args[0]) if args[0]
@@ -538,7 +541,7 @@ class Redis
538
541
  end
539
542
 
540
543
  def add_namespace(key)
541
- return key unless key && @namespace
544
+ return key unless key && namespace
542
545
 
543
546
  case key
544
547
  when Array
@@ -547,12 +550,12 @@ class Redis
547
550
  key.keys.each {|k| key[add_namespace(k)] = key.delete(k)}
548
551
  key
549
552
  else
550
- "#{@namespace}:#{key}"
553
+ "#{namespace}:#{key}"
551
554
  end
552
555
  end
553
556
 
554
557
  def rem_namespace(key)
555
- return key unless key && @namespace
558
+ return key unless key && namespace
556
559
 
557
560
  case key
558
561
  when Array
@@ -564,7 +567,7 @@ class Redis
564
567
  key.each { |k| yielder.yield rem_namespace(k) }
565
568
  end
566
569
  else
567
- key.to_s.sub(/\A#{@namespace}:/, '')
570
+ key.to_s.sub(/\A#{namespace}:/, '')
568
571
  end
569
572
  end
570
573
 
data/spec/redis_spec.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require File.dirname(__FILE__) + '/spec_helper'
4
4
 
5
5
  describe "redis" do
6
- @redis_version = Gem::Version.new(Redis.current.info["redis_version"])
6
+ @redis_version = Gem::Version.new(Redis.new.info["redis_version"])
7
7
  let(:redis_client) { @redis.respond_to?(:_client) ? @redis._client : @redis.client}
8
8
 
9
9
  before(:each) do
@@ -41,6 +41,17 @@ describe "redis" do
41
41
  expect(@namespaced.type('counter')).to eq('string')
42
42
  end
43
43
 
44
+ it "should work with Proc namespaces" do
45
+ namespace = Proc.new { :dynamic_ns }
46
+ namespaced = Redis::Namespace.new(namespace, redis: @redis)
47
+
48
+ expect(namespaced.get('foo')).to eq(nil)
49
+ namespaced.set('foo', 'chris')
50
+ expect(namespaced.get('foo')).to eq('chris')
51
+ @redis.set('foo', 'bob')
52
+ expect(@redis.get('foo')).to eq('bob')
53
+ end
54
+
44
55
  context 'when sending capital commands (issue 68)' do
45
56
  it 'should be able to use a namespace' do
46
57
  @namespaced.send('SET', 'fubar', 'quux')
@@ -95,6 +106,13 @@ describe "redis" do
95
106
  expect(@namespaced.lrange('bar',0,-1)).to eq(['bar'])
96
107
  end
97
108
 
109
+ it "should be able to use a namespace with getex" do
110
+ expect(@namespaced.set('mykey', 'Hello')).to eq('OK')
111
+ expect(@namespaced.getex('mykey', ex: 50)).to eq('Hello')
112
+ expect(@namespaced.get('mykey')).to eq('Hello')
113
+ expect(@namespaced.ttl('mykey')).to eq(50)
114
+ end
115
+
98
116
  it 'should be able to use a namespace with getbit' do
99
117
  @namespaced.set('foo','bar')
100
118
  expect(@namespaced.getbit('foo',1)).to eq(1)
@@ -170,15 +188,22 @@ describe "redis" do
170
188
  @namespaced.mset('foo', '1000', 'bar', '2000')
171
189
  expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
172
190
  expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
191
+
173
192
  @namespaced.mapped_mset('foo' => '3000', 'bar' => '5000')
174
193
  expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000' })
175
194
  expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '3000', 'bar' => '5000', 'baz' => nil})
195
+
196
+ @namespaced.mset(['foo', '4000'], ['baz', '6000'])
197
+ expect(@namespaced.mapped_mget('foo', 'bar', 'baz')).to eq({ 'foo' => '4000', 'bar' => '5000', 'baz' => '6000' })
176
198
  end
177
199
 
178
200
  it "should be able to use a namespace with msetnx" do
179
201
  @namespaced.msetnx('foo', '1000', 'bar', '2000')
180
202
  expect(@namespaced.mapped_mget('foo', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000' })
181
203
  expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => nil})
204
+
205
+ @namespaced.msetnx(['baz', '4000'])
206
+ expect(@namespaced.mapped_mget('foo', 'baz', 'bar')).to eq({ 'foo' => '1000', 'bar' => '2000', 'baz' => '4000'})
182
207
  end
183
208
 
184
209
  it "should be able to use a namespace with mapped_msetnx" do
@@ -687,7 +712,7 @@ describe "redis" do
687
712
  expect(result).to match_array(namespaced_keys)
688
713
  end
689
714
  end
690
- end if Redis.current.respond_to?(:scan)
715
+ end if Redis.new.respond_to?(:scan)
691
716
 
692
717
  context '#scan_each' do
693
718
  context 'when :match supplied' do
@@ -720,7 +745,7 @@ describe "redis" do
720
745
  end
721
746
  end
722
747
  end
723
- end if Redis.current.respond_to?(:scan_each)
748
+ end if Redis.new.respond_to?(:scan_each)
724
749
  end
725
750
 
726
751
  context 'hash scan methods' do
@@ -748,7 +773,7 @@ describe "redis" do
748
773
  expect(results).to match_array(@redis.hgetall('ns:hsh').to_a)
749
774
  end
750
775
  end
751
- end if Redis.current.respond_to?(:hscan)
776
+ end if Redis.new.respond_to?(:hscan)
752
777
 
753
778
  context '#hscan_each' do
754
779
  context 'when :match supplied' do
@@ -781,7 +806,7 @@ describe "redis" do
781
806
  end
782
807
  end
783
808
  end
784
- end if Redis.current.respond_to?(:hscan_each)
809
+ end if Redis.new.respond_to?(:hscan_each)
785
810
  end
786
811
 
787
812
  context 'set scan methods' do
@@ -809,7 +834,7 @@ describe "redis" do
809
834
  expect(results).to match_array(set)
810
835
  end
811
836
  end
812
- end if Redis.current.respond_to?(:sscan)
837
+ end if Redis.new.respond_to?(:sscan)
813
838
 
814
839
  context '#sscan_each' do
815
840
  context 'when :match supplied' do
@@ -842,7 +867,7 @@ describe "redis" do
842
867
  end
843
868
  end
844
869
  end
845
- end if Redis.current.respond_to?(:sscan_each)
870
+ end if Redis.new.respond_to?(:sscan_each)
846
871
  end
847
872
 
848
873
  context 'zset scan methods' do
@@ -872,7 +897,7 @@ describe "redis" do
872
897
  expect(results).to match_array(hash.to_a)
873
898
  end
874
899
  end
875
- end if Redis.current.respond_to?(:zscan)
900
+ end if Redis.new.respond_to?(:zscan)
876
901
 
877
902
  context '#zscan_each' do
878
903
  context 'when :match supplied' do
@@ -905,7 +930,7 @@ describe "redis" do
905
930
  end
906
931
  end
907
932
  end
908
- end if Redis.current.respond_to?(:zscan_each)
933
+ end if Redis.new.respond_to?(:zscan_each)
909
934
  end
910
935
  end
911
936
  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.8.2
4
+ version: 1.9.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-03-07 00:00:00.000000000 Z
15
+ date: 2022-08-13 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: 3.0.4
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: 3.0.4
30
+ version: '4'
30
31
  - !ruby/object:Gem::Dependency
31
32
  name: rake
32
33
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +79,7 @@ email:
78
79
  - hone02@gmail.com
79
80
  - steve@steveklabnik.com
80
81
  - me@yaauie.com
82
+ - mike@mikebian.co
81
83
  executables: []
82
84
  extensions: []
83
85
  extra_rdoc_files: []
@@ -97,8 +99,9 @@ licenses:
97
99
  metadata:
98
100
  bug_tracker_uri: https://github.com/resque/redis-namespace/issues
99
101
  changelog_uri: https://github.com/resque/redis-namespace/blob/master/CHANGELOG.md
100
- documentation_uri: https://www.rubydoc.info/gems/redis-namespace/1.8.2
101
- source_code_uri: https://github.com/resque/redis-namespace/tree/v1.8.2
102
+ documentation_uri: https://www.rubydoc.info/gems/redis-namespace/1.9.0
103
+ source_code_uri: https://github.com/resque/redis-namespace/tree/v1.9.0
104
+ rubygems_mfa_required: 'true'
102
105
  post_install_message:
103
106
  rdoc_options: []
104
107
  require_paths:
@@ -114,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
117
  - !ruby/object:Gem::Version
115
118
  version: '0'
116
119
  requirements: []
117
- rubygems_version: 3.1.2
120
+ rubygems_version: 3.1.6
118
121
  signing_key:
119
122
  specification_version: 4
120
123
  summary: Namespaces Redis commands.