redis-namespace 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redis/namespace.rb +15 -2
- data/lib/redis/namespace/version.rb +7 -0
- data/spec/redis_spec.rb +25 -3
- metadata +28 -15
- checksums.yaml +0 -7
data/lib/redis/namespace.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'redis'
|
2
|
+
require 'redis/namespace/version'
|
2
3
|
|
3
4
|
class Redis
|
4
5
|
class Namespace
|
@@ -34,6 +35,13 @@ class Redis
|
|
34
35
|
# Add the namespace to every other argument, e.g.
|
35
36
|
# MSET key1 value1 key2 value2 =>
|
36
37
|
# MSET namespace:key1 value1 namespace:key2 value2
|
38
|
+
# :sort
|
39
|
+
# Add namespace to first argument if it is non-nil
|
40
|
+
# Add namespace to second arg's :by and :store if second arg is a Hash
|
41
|
+
# Add namespace to each element in second arg's :get if second arg is
|
42
|
+
# a Hash; forces second arg's :get to be an Array if present.
|
43
|
+
# :eval_style
|
44
|
+
# Add namespace to each element in keys argument (via options hash or multi-args)
|
37
45
|
#
|
38
46
|
# The second element in the value array describes how to modify
|
39
47
|
# the return value of the Redis call. It can be one of:
|
@@ -244,9 +252,14 @@ class Redis
|
|
244
252
|
method_missing(:exec)
|
245
253
|
end
|
246
254
|
|
255
|
+
def eval(*args)
|
256
|
+
method_missing(:eval, *args)
|
257
|
+
end
|
258
|
+
|
247
259
|
def method_missing(command, *args, &block)
|
248
|
-
|
249
|
-
|
260
|
+
command_for_lookup = command.to_s.downcase
|
261
|
+
handling = COMMANDS[command_for_lookup] ||
|
262
|
+
COMMANDS[ALIASES[command_for_lookup]]
|
250
263
|
|
251
264
|
# redis-namespace does not know how to handle this command.
|
252
265
|
# Passing it to @redis as is, where redis-namespace shows
|
data/spec/redis_spec.rb
CHANGED
@@ -39,6 +39,14 @@ describe "redis" do
|
|
39
39
|
@namespaced.type('counter').should eq('string')
|
40
40
|
end
|
41
41
|
|
42
|
+
context 'when sending capital commands (issue 68)' do
|
43
|
+
it 'should be able to use a namespace' do
|
44
|
+
@namespaced.send('SET', 'fubar', 'quux')
|
45
|
+
@redis.get('fubar').should be_nil
|
46
|
+
@namespaced.get('fubar').should eq 'quux'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
42
50
|
it "should be able to use a namespace with bpop" do
|
43
51
|
@namespaced.rpush "foo", "string"
|
44
52
|
@namespaced.rpush "foo", "ns:string"
|
@@ -143,12 +151,11 @@ describe "redis" do
|
|
143
151
|
end
|
144
152
|
|
145
153
|
it "should be able to use a namespace with mapped_msetnx" do
|
146
|
-
puts @namespaced.keys.inspect
|
147
154
|
@namespaced.set('foo','1')
|
148
155
|
@namespaced.mapped_msetnx('foo'=>'1000', 'bar'=>'2000').should be_false
|
149
|
-
@namespaced.mapped_mget('foo', 'bar').should
|
156
|
+
@namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1', 'bar' => nil })
|
150
157
|
@namespaced.mapped_msetnx('bar'=>'2000', 'baz'=>'1000').should be_true
|
151
|
-
@namespaced.mapped_mget('foo', 'bar').should
|
158
|
+
@namespaced.mapped_mget('foo', 'bar').should eq({ 'foo' => '1', 'bar' => '2000' })
|
152
159
|
end
|
153
160
|
|
154
161
|
it "should be able to use a namespace with hashes" do
|
@@ -433,6 +440,21 @@ describe "redis" do
|
|
433
440
|
should eq(%w[ns:k1 ns:k2])
|
434
441
|
end
|
435
442
|
end
|
443
|
+
|
444
|
+
context "in a nested namespace" do
|
445
|
+
let(:nested_namespace) { Redis::Namespace.new(:nest, :redis => @namespaced) }
|
446
|
+
let(:sha) { nested_namespace.script(:load, "return {KEYS[1], KEYS[2]}") }
|
447
|
+
|
448
|
+
it "should namespace eval keys passed in as hash args" do
|
449
|
+
nested_namespace.
|
450
|
+
eval("return {KEYS[1], KEYS[2]}", :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
451
|
+
should eq(%w[ns:nest:k1 ns:nest:k2])
|
452
|
+
end
|
453
|
+
it "should namespace evalsha keys passed in as hash args" do
|
454
|
+
nested_namespace.evalsha(sha, :keys => %w[k1 k2], :argv => %w[arg1 arg2]).
|
455
|
+
should eq(%w[ns:nest:k1 ns:nest:k2])
|
456
|
+
end
|
457
|
+
end
|
436
458
|
end
|
437
459
|
end
|
438
460
|
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-namespace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Chris Wanstrath
|
@@ -10,54 +11,63 @@ authors:
|
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2013-
|
14
|
+
date: 2013-11-03 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: redis
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
18
20
|
requirements:
|
19
21
|
- - ~>
|
20
22
|
- !ruby/object:Gem::Version
|
21
|
-
version: 3.0.
|
23
|
+
version: 3.0.4
|
22
24
|
type: :runtime
|
23
25
|
prerelease: false
|
24
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
25
28
|
requirements:
|
26
29
|
- - ~>
|
27
30
|
- !ruby/object:Gem::Version
|
28
|
-
version: 3.0.
|
31
|
+
version: 3.0.4
|
29
32
|
- !ruby/object:Gem::Dependency
|
30
33
|
name: rake
|
31
34
|
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
32
36
|
requirements:
|
33
|
-
- - '>='
|
37
|
+
- - ! '>='
|
34
38
|
- !ruby/object:Gem::Version
|
35
39
|
version: '0'
|
36
40
|
type: :development
|
37
41
|
prerelease: false
|
38
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
39
44
|
requirements:
|
40
|
-
- - '>='
|
45
|
+
- - ! '>='
|
41
46
|
- !ruby/object:Gem::Version
|
42
47
|
version: '0'
|
43
48
|
- !ruby/object:Gem::Dependency
|
44
49
|
name: rspec
|
45
50
|
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
46
52
|
requirements:
|
47
|
-
- - '>='
|
53
|
+
- - ! '>='
|
48
54
|
- !ruby/object:Gem::Version
|
49
55
|
version: '0'
|
50
56
|
type: :development
|
51
57
|
prerelease: false
|
52
58
|
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
53
60
|
requirements:
|
54
|
-
- - '>='
|
61
|
+
- - ! '>='
|
55
62
|
- !ruby/object:Gem::Version
|
56
63
|
version: '0'
|
57
|
-
description:
|
58
|
-
|
64
|
+
description: ! 'Adds a Redis::Namespace class which can be used to namespace calls
|
65
|
+
|
59
66
|
to Redis. This is useful when using a single instance of Redis with
|
67
|
+
|
60
68
|
multiple, different applications.
|
69
|
+
|
70
|
+
'
|
61
71
|
email:
|
62
72
|
- chris@ozmm.org
|
63
73
|
- hone02@gmail.com
|
@@ -69,31 +79,34 @@ files:
|
|
69
79
|
- README.md
|
70
80
|
- Rakefile
|
71
81
|
- LICENSE
|
82
|
+
- lib/redis/namespace/version.rb
|
72
83
|
- lib/redis/namespace.rb
|
73
84
|
- lib/redis-namespace.rb
|
74
85
|
- spec/redis_spec.rb
|
75
86
|
- spec/spec_helper.rb
|
76
87
|
homepage: http://github.com/resque/redis-namespace
|
77
88
|
licenses: []
|
78
|
-
metadata: {}
|
79
89
|
post_install_message:
|
80
90
|
rdoc_options: []
|
81
91
|
require_paths:
|
82
92
|
- lib
|
83
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
84
95
|
requirements:
|
85
|
-
- - '>='
|
96
|
+
- - ! '>='
|
86
97
|
- !ruby/object:Gem::Version
|
87
98
|
version: '0'
|
88
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
89
101
|
requirements:
|
90
|
-
- - '>='
|
102
|
+
- - ! '>='
|
91
103
|
- !ruby/object:Gem::Version
|
92
104
|
version: '0'
|
93
105
|
requirements: []
|
94
106
|
rubyforge_project:
|
95
|
-
rubygems_version:
|
107
|
+
rubygems_version: 1.8.24
|
96
108
|
signing_key:
|
97
|
-
specification_version:
|
109
|
+
specification_version: 3
|
98
110
|
summary: Namespaces Redis commands.
|
99
111
|
test_files: []
|
112
|
+
has_rdoc: false
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 838bcd2a161520a3d12b854bc1a441005c7a1d71
|
4
|
-
data.tar.gz: ea531ab8ea4ff3fcca0b23bdd98ca9e35eb43755
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 2af8b6ac91666d5f686d700886637b70fca79374768b076f302540bcc739f1eacd8eec03849bc554e4891b4a99f11a525be481a972eb24fa315ca42b808f1390
|
7
|
-
data.tar.gz: 2cdff48f02a69335dd95a2c5ee5974cb4fff6676ff185e27a5d61de12ba5e00d2dc6da82aecccee538cc6c28e4d33e0e08d13f725afee7529fc5934aa200a298
|