redis-namespace 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of redis-namespace might be problematic. Click here for more details.
- data/Rakefile +1 -1
- data/lib/redis/namespace.rb +41 -0
- data/spec/redis_spec.rb +26 -2
- metadata +2 -2
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ begin
|
|
15
15
|
gemspec.email = "chris@ozmm.org"
|
16
16
|
gemspec.homepage = "http://github.com/defunkt/redis-namespace"
|
17
17
|
gemspec.authors = ["Chris Wanstrath"]
|
18
|
-
gemspec.version = '0.
|
18
|
+
gemspec.version = '0.2.0'
|
19
19
|
end
|
20
20
|
rescue LoadError
|
21
21
|
puts "Jeweler not available. Install it with:"
|
data/lib/redis/namespace.rb
CHANGED
@@ -8,7 +8,10 @@ class Redis
|
|
8
8
|
# $('.vt li a').map(function(){ return $(this).text().toLowerCase() }).sort()
|
9
9
|
COMMANDS = [
|
10
10
|
"auth",
|
11
|
+
"bgrewriteaof",
|
11
12
|
"bgsave",
|
13
|
+
"blpop",
|
14
|
+
"brpop",
|
12
15
|
"dbsize",
|
13
16
|
"decr",
|
14
17
|
"decrby",
|
@@ -35,11 +38,14 @@ class Redis
|
|
35
38
|
"mget",
|
36
39
|
"monitor",
|
37
40
|
"move",
|
41
|
+
"mset",
|
42
|
+
"msetnx",
|
38
43
|
"quit",
|
39
44
|
"randomkey",
|
40
45
|
"rename",
|
41
46
|
"renamenx",
|
42
47
|
"rpop",
|
48
|
+
"rpoplpush",
|
43
49
|
"rpush",
|
44
50
|
"sadd",
|
45
51
|
"save",
|
@@ -57,15 +63,28 @@ class Redis
|
|
57
63
|
"smembers",
|
58
64
|
"smove",
|
59
65
|
"sort",
|
66
|
+
"spop",
|
67
|
+
"srandmember",
|
60
68
|
"srem",
|
61
69
|
"sunion",
|
62
70
|
"sunionstore",
|
63
71
|
"ttl",
|
64
72
|
"type",
|
73
|
+
"zadd",
|
74
|
+
"zcard",
|
75
|
+
"zincrby",
|
76
|
+
"zrange",
|
77
|
+
"zrangebyscore",
|
78
|
+
"zrem",
|
79
|
+
"zremrangebyscore",
|
80
|
+
"zrevrange",
|
81
|
+
"zscore",
|
65
82
|
"[]",
|
66
83
|
"[]="
|
67
84
|
]
|
68
85
|
|
86
|
+
attr_accessor :namespace
|
87
|
+
|
69
88
|
def initialize(namespace, options = {})
|
70
89
|
@namespace = namespace
|
71
90
|
@redis = options[:redis]
|
@@ -91,6 +110,14 @@ class Redis
|
|
91
110
|
call_command([:mget] + keys)
|
92
111
|
end
|
93
112
|
|
113
|
+
def mset(keys)
|
114
|
+
call_mset(:mset, keys)
|
115
|
+
end
|
116
|
+
|
117
|
+
def msetnx(keys)
|
118
|
+
call_mset(:msetnx, keys)
|
119
|
+
end
|
120
|
+
|
94
121
|
def method_missing(command, *args, &block)
|
95
122
|
if COMMANDS.include?(command.to_s) && args[0]
|
96
123
|
args[0] = "#{@namespace}:#{args[0]}"
|
@@ -98,5 +125,19 @@ class Redis
|
|
98
125
|
|
99
126
|
@redis.send(command, *args, &block)
|
100
127
|
end
|
128
|
+
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
|
133
|
+
def call_mset(command, keys)
|
134
|
+
if @namespace
|
135
|
+
namespaced_keys = {}
|
136
|
+
keys.each { |key, value| namespaced_keys["#{@namespace}:#{key}"] = value }
|
137
|
+
keys = namespaced_keys
|
138
|
+
end
|
139
|
+
|
140
|
+
call_command([command] + [keys])
|
141
|
+
end
|
101
142
|
end
|
102
143
|
end
|
data/spec/redis_spec.rb
CHANGED
@@ -36,11 +36,35 @@ describe "redis" do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should be able to use a namespace with mget" do
|
39
|
-
r = Redis::Namespace.new(:ns, :redis => @redis)
|
40
|
-
|
41
39
|
@namespaced['foo'] = 1000
|
42
40
|
@namespaced['bar'] = 2000
|
43
41
|
@namespaced.mapped_mget('foo', 'bar').should == { 'foo' => '1000', 'bar' => '2000' }
|
44
42
|
@namespaced.mapped_mget('foo', 'baz', 'bar').should == {'foo'=>'1000', 'bar'=>'2000'}
|
45
43
|
end
|
44
|
+
|
45
|
+
it "should be able to use a namespace with mset" do
|
46
|
+
@namespaced.mset('foo' => '1000', 'bar' => '2000')
|
47
|
+
@namespaced.mapped_mget('foo', 'bar').should == { 'foo' => '1000', 'bar' => '2000' }
|
48
|
+
@namespaced.mapped_mget('foo', 'baz', 'bar').should == { 'foo' => '1000', 'bar' => '2000'}
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should be able to use a namespace with msetnx" do
|
52
|
+
@namespaced.msetnx('foo' => '1000', 'bar' => '2000')
|
53
|
+
@namespaced.mapped_mget('foo', 'bar').should == { 'foo' => '1000', 'bar' => '2000' }
|
54
|
+
@namespaced.mapped_mget('foo', 'baz', 'bar').should == { 'foo' => '1000', 'bar' => '2000'}
|
55
|
+
end
|
56
|
+
|
57
|
+
it "can change its namespace" do
|
58
|
+
@namespaced['foo'].should == nil
|
59
|
+
@namespaced['foo'] = 'chris'
|
60
|
+
@namespaced['foo'].should == 'chris'
|
61
|
+
|
62
|
+
@namespaced.namespace.should == :ns
|
63
|
+
@namespaced.namespace = :spec
|
64
|
+
@namespaced.namespace.should == :spec
|
65
|
+
|
66
|
+
@namespaced['foo'].should == nil
|
67
|
+
@namespaced['foo'] = 'chris'
|
68
|
+
@namespaced['foo'].should == 'chris'
|
69
|
+
end
|
46
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-namespace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-25 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|