redis-namespace 1.5.3 → 1.8.1

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
- SHA1:
3
- metadata.gz: d8a331998a5b4c5b9f5f323da912dc2e4555a2db
4
- data.tar.gz: da08789df8269adf261ff47f7c1da894718ddc88
2
+ SHA256:
3
+ metadata.gz: 781a6361b78e31842c9fe934161b83e1acf9d1c1ef50cd015694b78582b461ac
4
+ data.tar.gz: a0856e98fb69b1063c460ef1479dd57a4659741612b398d3fac2d4bb3727e1b0
5
5
  SHA512:
6
- metadata.gz: 68d3325257b3c5a9ba0a7e461c39d30ce9de639304e8926e809e5f51256c5da41a8cdb2f29a5c2cd5c700032dc6d4e5b42be3e29327bcdaf0439c93f4db03f0a
7
- data.tar.gz: cffdb70935cade3a38e66e46a71ad9082afb074ebbbc05627113b6504e5b6337ec8c917734eeaf871e6dea271e9483bdfa11b22bdf1b772eab04e0f973fc3bdc
6
+ metadata.gz: caf163b05d1f4c5f08a29d4d1f977d666f1a627b582af762f50d883df64f0f2139fe132918edbc6c59d9259f386f7ed7a094da3493579072f25d9c957da7e7eb
7
+ data.tar.gz: 951f20c3aaedd77400f34b161fb642d39ff0a4e8a619506441288f6671043a3bfd3e1f18e13a62fc8e014f79d989246fcb51b351f4d3f1b6f3a2a6ce8f17bd41
data/LICENSE CHANGED
@@ -1,20 +1,21 @@
1
+ MIT License
2
+
1
3
  Copyright (c) 2009 Chris Wanstrath
2
4
 
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
10
11
 
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
13
14
 
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -3,13 +3,13 @@ redis-namespace
3
3
 
4
4
  Redis::Namespace provides an interface to a namespaced subset of your [redis][] keyspace (e.g., keys with a common beginning), and requires the [redis-rb][] gem.
5
5
 
6
- ~~~ irb
6
+ ```ruby
7
7
  require 'redis-namespace'
8
8
  # => true
9
9
 
10
10
  redis_connection = Redis.new
11
11
  # => #<Redis client v3.1.0 for redis://127.0.0.1:6379/0>
12
- namespaced_redis = Redis::Namespace.new(:ns, :redis => redis_connection)
12
+ namespaced_redis = Redis::Namespace.new(:ns, redis: redis_connection)
13
13
  # => #<Redis::Namespace v1.5.0 with client v3.1.0 for redis://127.0.0.1:6379/0/ns>
14
14
 
15
15
  namespaced_redis.set('foo', 'bar') # redis_connection.set('ns:foo', 'bar')
@@ -20,6 +20,8 @@ namespaced_redis.set('foo', 'bar') # redis_connection.set('ns:foo', 'bar')
20
20
 
21
21
  namespaced_redis.get('foo')
22
22
  # => "bar"
23
+ redis_connection.get('foo')
24
+ # => nil
23
25
  redis_connection.get('ns:foo')
24
26
  # => "bar"
25
27
 
@@ -29,7 +31,7 @@ namespaced_redis.get('foo')
29
31
  # => nil
30
32
  redis_connection.get('ns:foo')
31
33
  # => nil
32
- ~~~
34
+ ```
33
35
 
34
36
  Installation
35
37
  ============
@@ -42,20 +44,18 @@ From the command line:
42
44
 
43
45
  Or in your Gemfile:
44
46
 
45
- ~~~ ruby
47
+ ```ruby
46
48
  gem 'redis-namespace'
47
- ~~~
49
+ ```
48
50
 
49
51
  Caveats
50
52
  =======
51
53
 
52
- `Redis::Namespace` provides a namespaced interface to `Redis` by keeping an internal registry of the method signatures in `Redis` provided by the redis-rb gem;
53
- we keep track of which arguments need the namespace added, and which return values need the namespace removed.
54
+ `Redis::Namespace` provides a namespaced interface to `Redis` by keeping an internal registry of the method signatures in `Redis` provided by the [redis-rb][] gem; we keep track of which arguments need the namespace added, and which return values need the namespace removed.
54
55
 
55
56
  Blind Passthrough
56
57
  -----------------
57
- If your version of this gem doesn't know about a particular command, it can't namespace it.
58
- Historically, this has meant that Redis::Namespace blindly passes unknown commands on to the underlying redis connection without modification which can lead to surprising effects.
58
+ If your version of this gem doesn't know about a particular command, it can't namespace it. Historically, this has meant that Redis::Namespace blindly passes unknown commands on to the underlying redis connection without modification which can lead to surprising effects.
59
59
 
60
60
  As of v1.5.0, blind passthrough has been deprecated, and the functionality will be removed entirely in 2.0.
61
61
 
@@ -63,19 +63,16 @@ If you come across a command that is not yet supported, please open an issue on
63
63
 
64
64
  Administrative Commands
65
65
  -----------------------
66
- The effects of some redis commands cannot be limited to a particular namespace (e.g., `FLUSHALL`, which literally truncates all databases in your redis server, regardless of keyspace).
67
- Historically, this has meant that Redis::Namespace intentionally passes administrative commands on to the underlying redis connection without modification, which can lead to surprising effects.
66
+ The effects of some redis commands cannot be limited to a particular namespace (e.g., `FLUSHALL`, which literally truncates all databases in your redis server, regardless of keyspace). Historically, this has meant that Redis::Namespace intentionally passes administrative commands on to the underlying redis connection without modification, which can lead to surprising effects.
68
67
 
69
- As of v1.6.0, the direct use of administrative commands has been deprecated, and the functionality will be removed entirely in 2.0;
70
- while such commands are often useful for testing or administration, their meaning is inherently hidden when placed behind an interface that implies it will namespace everything.
68
+ As of v1.6.0, the direct use of administrative commands has been deprecated, and the functionality will be removed entirely in 2.0; while such commands are often useful for testing or administration, their meaning is inherently hidden when placed behind an interface that implies it will namespace everything.
71
69
 
72
- The prefered way to send an administrative command is on the redis connection
73
- itself, which is publicly exposed as `Redis::Namespace#redis`:
70
+ The prefered way to send an administrative command is on the redis connection itself, which is publicly exposed as `Redis::Namespace#redis`:
74
71
 
75
- ~~~ ruby
72
+ ```ruby
76
73
  namespaced.redis.flushall()
77
74
  # => "OK"
78
- ~~~
75
+ ```
79
76
 
80
77
  2.x Planned Breaking Changes
81
78
  ============================
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Redis
4
4
  class Namespace
5
- VERSION = '1.5.3'
5
+ VERSION = '1.8.1'
6
6
  end
7
7
  end
@@ -57,15 +57,19 @@ class Redis
57
57
  "append" => [ :first ],
58
58
  "bitcount" => [ :first ],
59
59
  "bitop" => [ :exclude_first ],
60
+ "bitpos" => [ :first ],
60
61
  "blpop" => [ :exclude_last, :first ],
61
62
  "brpop" => [ :exclude_last, :first ],
62
63
  "brpoplpush" => [ :exclude_last ],
64
+ "bzpopmin" => [ :first ],
65
+ "bzpopmax" => [ :first ],
63
66
  "debug" => [ :exclude_first ],
64
67
  "decr" => [ :first ],
65
68
  "decrby" => [ :first ],
66
69
  "del" => [ :all ],
67
70
  "dump" => [ :first ],
68
- "exists" => [ :first ],
71
+ "exists" => [ :all ],
72
+ "exists?" => [ :all ],
69
73
  "expire" => [ :first ],
70
74
  "expireat" => [ :first ],
71
75
  "eval" => [ :eval_style ],
@@ -160,27 +164,31 @@ class Redis
160
164
  "sunionstore" => [ :all ],
161
165
  "ttl" => [ :first ],
162
166
  "type" => [ :first ],
167
+ "unlink" => [ :all ],
163
168
  "unsubscribe" => [ :all ],
164
169
  "zadd" => [ :first ],
165
170
  "zcard" => [ :first ],
166
171
  "zcount" => [ :first ],
167
172
  "zincrby" => [ :first ],
168
173
  "zinterstore" => [ :exclude_options ],
174
+ "zpopmin" => [ :first ],
175
+ "zpopmax" => [ :first ],
169
176
  "zrange" => [ :first ],
170
177
  "zrangebyscore" => [ :first ],
178
+ "zrangebylex" => [ :first ],
171
179
  "zrank" => [ :first ],
172
180
  "zrem" => [ :first ],
173
181
  "zremrangebyrank" => [ :first ],
174
182
  "zremrangebyscore" => [ :first ],
183
+ "zremrangebylex" => [ :first ],
175
184
  "zrevrange" => [ :first ],
176
185
  "zrevrangebyscore" => [ :first ],
186
+ "zrevrangebylex" => [ :first ],
177
187
  "zrevrank" => [ :first ],
178
188
  "zscan" => [ :first ],
179
189
  "zscan_each" => [ :first ],
180
190
  "zscore" => [ :first ],
181
- "zunionstore" => [ :exclude_options ],
182
- "[]" => [ :first ],
183
- "[]=" => [ :first ]
191
+ "zunionstore" => [ :exclude_options ]
184
192
  }
185
193
  TRANSACTION_COMMANDS = {
186
194
  "discard" => [],
@@ -241,6 +249,7 @@ class Redis
241
249
  @deprecations = !!options.fetch(:deprecations) do
242
250
  ENV['REDIS_NAMESPACE_DEPRECATIONS']
243
251
  end
252
+ @has_new_client_method = @redis.respond_to?(:_client)
244
253
  end
245
254
 
246
255
  def deprecations?
@@ -252,7 +261,13 @@ class Redis
252
261
  end
253
262
 
254
263
  def client
255
- @redis.client
264
+ warn("The client method is deprecated as of redis-rb 4.0.0, please use the new _client" +
265
+ "method instead. Support for the old method will be removed in redis-namespace 2.0.") if @has_new_client_method && deprecations?
266
+ _client
267
+ end
268
+
269
+ def _client
270
+ @has_new_client_method ? @redis._client : @redis.client # for redis-4.0.0
256
271
  end
257
272
 
258
273
  # Ruby defines a now deprecated type method so we need to override it here
@@ -265,7 +280,9 @@ class Redis
265
280
 
266
281
  # emulate Ruby 1.9+ and keep respond_to_missing? logic together.
267
282
  def respond_to?(command, include_private=false)
268
- super or respond_to_missing?(command, include_private)
283
+ return !deprecations? if DEPRECATED_COMMANDS.include?(command.to_s.downcase)
284
+
285
+ respond_to_missing?(command, include_private) or super
269
286
  end
270
287
 
271
288
  def keys(query = nil)
@@ -293,6 +310,14 @@ class Redis
293
310
  @namespace
294
311
  end
295
312
 
313
+ def full_namespace
314
+ redis.is_a?(Namespace) ? "#{redis.full_namespace}:#{namespace}" : namespace.to_s
315
+ end
316
+
317
+ def connection
318
+ @redis.connection.tap { |info| info[:namespace] = @namespace }
319
+ end
320
+
296
321
  def exec
297
322
  call_with_namespace(:exec)
298
323
  end
@@ -300,16 +325,14 @@ class Redis
300
325
  def eval(*args)
301
326
  call_with_namespace(:eval, *args)
302
327
  end
328
+ ruby2_keywords(:eval) if respond_to?(:ruby2_keywords, true)
303
329
 
304
- def method_missing(command, *args, &block)
305
- normalized_command = command.to_s.downcase
330
+ ADMINISTRATIVE_COMMANDS.keys.each do |command|
331
+ define_method(command) do |*args, &block|
332
+ raise NoMethodError if deprecations?
306
333
 
307
- if ADMINISTRATIVE_COMMANDS.include?(normalized_command)
308
- # administrative commands usage is deprecated and will be removed in 2.0
309
- # redis-namespace cannot safely apply a namespace to their effects.
310
- return super if deprecations?
311
334
  if warning?
312
- warn("Passing '#{normalized_command}' command to redis as is; " +
335
+ warn("Passing '#{command}' command to redis as is; " +
313
336
  "administrative commands cannot be effectively namespaced " +
314
337
  "and should be called on the redis connection directly; " +
315
338
  "passthrough has been deprecated and will be removed in " +
@@ -317,8 +340,25 @@ class Redis
317
340
  )
318
341
  end
319
342
  call_with_namespace(command, *args, &block)
320
- elsif COMMANDS.include?(normalized_command)
343
+ end
344
+ ruby2_keywords(command) if respond_to?(:ruby2_keywords, true)
345
+ end
346
+
347
+ COMMANDS.keys.each do |command|
348
+ next if ADMINISTRATIVE_COMMANDS.include?(command)
349
+ next if method_defined?(command)
350
+
351
+ define_method(command) do |*args, &block|
321
352
  call_with_namespace(command, *args, &block)
353
+ end
354
+ ruby2_keywords(command) if respond_to?(:ruby2_keywords, true)
355
+ end
356
+
357
+ def method_missing(command, *args, &block)
358
+ normalized_command = command.to_s.downcase
359
+
360
+ if COMMANDS.include?(normalized_command)
361
+ send(normalized_command, *args, &block)
322
362
  elsif @redis.respond_to?(normalized_command) && !deprecations?
323
363
  # blind passthrough is deprecated and will be removed in 2.0
324
364
  # redis-namespace does not know how to handle this command.
@@ -334,18 +374,17 @@ class Redis
334
374
  super
335
375
  end
336
376
  end
377
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
337
378
 
338
379
  def inspect
339
380
  "<#{self.class.name} v#{VERSION} with client v#{Redis::VERSION} "\
340
- "for #{@redis.id}/#{@namespace}>"
381
+ "for #{@redis.id}/#{full_namespace}>"
341
382
  end
342
383
 
343
384
  def respond_to_missing?(command, include_all=false)
344
385
  normalized_command = command.to_s.downcase
345
386
 
346
387
  case
347
- when DEPRECATED_COMMANDS.include?(normalized_command)
348
- !deprecations?
349
388
  when COMMANDS.include?(normalized_command)
350
389
  true
351
390
  when !deprecations? && redis.respond_to?(command, include_all)
@@ -371,6 +410,7 @@ class Redis
371
410
  case before
372
411
  when :first
373
412
  args[0] = add_namespace(args[0]) if args[0]
413
+ args[-1] = ruby2_keywords_hash(args[-1]) if args[-1].is_a?(Hash)
374
414
  when :all
375
415
  args = add_namespace(args)
376
416
  when :exclude_first
@@ -383,7 +423,7 @@ class Redis
383
423
  args.push(last) if last
384
424
  when :exclude_options
385
425
  if args.last.is_a?(Hash)
386
- last = args.pop
426
+ last = ruby2_keywords_hash(args.pop)
387
427
  args = add_namespace(args)
388
428
  args.push(last)
389
429
  else
@@ -403,6 +443,7 @@ class Redis
403
443
  args[1][:get].each_index do |i|
404
444
  args[1][:get][i] = add_namespace(args[1][:get][i]) unless args[1][:get][i] == "#"
405
445
  end
446
+ args[1] = ruby2_keywords_hash(args[1])
406
447
  end
407
448
  when :eval_style
408
449
  # redis.eval() and evalsha() can either take the form:
@@ -423,7 +464,7 @@ class Redis
423
464
  when :scan_style
424
465
  options = (args.last.kind_of?(Hash) ? args.pop : {})
425
466
  options[:match] = add_namespace(options.fetch(:match, '*'))
426
- args << options
467
+ args << ruby2_keywords_hash(options)
427
468
 
428
469
  if block
429
470
  original_block = block
@@ -449,9 +490,20 @@ class Redis
449
490
 
450
491
  result
451
492
  end
493
+ ruby2_keywords(:call_with_namespace) if respond_to?(:ruby2_keywords, true)
452
494
 
453
495
  private
454
496
 
497
+ if Hash.respond_to?(:ruby2_keywords_hash)
498
+ def ruby2_keywords_hash(kwargs)
499
+ Hash.ruby2_keywords_hash(kwargs)
500
+ end
501
+ else
502
+ def ruby2_keywords_hash(kwargs)
503
+ kwargs
504
+ end
505
+ end
506
+
455
507
  # Avoid modifying the caller's (pass-by-reference) arguments.
456
508
  def clone_args(arg)
457
509
  if arg.is_a?(Array)
@@ -43,7 +43,7 @@ describe Redis::Namespace do
43
43
  its(:deprecations?) { should be true }
44
44
 
45
45
  context('with an unhandled command') do
46
- it { should_not respond_to :unhandled }
46
+ it { is_expected.not_to respond_to :unhandled }
47
47
 
48
48
  it('raises a NoMethodError') do
49
49
  expect do
@@ -53,7 +53,7 @@ describe Redis::Namespace do
53
53
  end
54
54
 
55
55
  context('with an administrative command') do
56
- it { should_not respond_to :flushdb }
56
+ it { is_expected.not_to respond_to :flushdb }
57
57
 
58
58
  it('raises a NoMethodError') do
59
59
  expect do
@@ -69,7 +69,7 @@ describe Redis::Namespace do
69
69
  its(:deprecations?) { should be false }
70
70
 
71
71
  context('with an an unhandled command') do
72
- it { should respond_to :unhandled }
72
+ it { is_expected.to respond_to :unhandled }
73
73
 
74
74
  it 'blindly passes through' do
75
75
  expect(redis).to receive(:unhandled)
@@ -106,7 +106,7 @@ describe Redis::Namespace do
106
106
  end
107
107
 
108
108
  context('with an administrative command') do
109
- it { should respond_to :flushdb }
109
+ it { is_expected.to respond_to :flushdb }
110
110
  it 'processes the command' do
111
111
  expect(redis).to receive(:flushdb)
112
112
  capture_stderr { namespaced.flushdb }