spymemcached.jruby 1.0.0-universal-java-1.7 → 1.0.1-universal-java-1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spymemcached.rb +11 -3
- data/lib/spymemcached_adapter.jar +0 -0
- data/test/spymemcached_test.rb +24 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdb378d078ec5deb37b38320e38e1a0961c979a4
|
4
|
+
data.tar.gz: 380044da20a32a1211d5fba6b6aa3b7cf239703f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f288aacb5527b67704d0bb07b6c3f28c9bd0cfffba6a66b90eb24f3e6914aa13d3889fb17216a89a9d980a30d0aa413670b6f89cb5ed16c0f7851f0eb43426d
|
7
|
+
data.tar.gz: 95feaed19b2eb5eea91f895b0fd51adaa1b50f185be56b89f6d6d8cf5fc31df069c7eb85a4ec81eebe3a986481f5562290eb7b397645d1a7b2f34a618698f612
|
data/lib/spymemcached.rb
CHANGED
@@ -32,6 +32,9 @@ class Spymemcached
|
|
32
32
|
def initialize(servers=['localhost:11211'], options={})
|
33
33
|
@servers, @options = Array(servers).join(','), DEFAULT_OPTIONS.merge(options)
|
34
34
|
@client = SpymemcachedAdapter.new(@servers, @options)
|
35
|
+
@namespace = if @options[:namespace]
|
36
|
+
@options[:namespace].is_a?(Proc) ? @options[:namespace] : lambda { @options[:namespace] }
|
37
|
+
end
|
35
38
|
at_exit { shutdown }
|
36
39
|
end
|
37
40
|
|
@@ -124,12 +127,17 @@ class Spymemcached
|
|
124
127
|
end
|
125
128
|
|
126
129
|
def ns(key)
|
127
|
-
|
130
|
+
return key unless namespace
|
131
|
+
"#{namespace.call}:#{key}"
|
128
132
|
end
|
129
133
|
|
130
134
|
def unns(k)
|
131
|
-
return k unless
|
132
|
-
@ns_size ||=
|
135
|
+
return k unless namespace
|
136
|
+
@ns_size ||= namespace.call.size + 1
|
133
137
|
k[@ns_size..-1]
|
134
138
|
end
|
139
|
+
|
140
|
+
def namespace
|
141
|
+
@namespace
|
142
|
+
end
|
135
143
|
end
|
Binary file
|
data/test/spymemcached_test.rb
CHANGED
@@ -8,30 +8,37 @@ class SpymemcachedTest < Test::Unit::TestCase
|
|
8
8
|
|
9
9
|
def test_expiry
|
10
10
|
@client.add('add_key1', 'v1', 0)
|
11
|
-
@client.add('add_key2', 'v2',
|
11
|
+
@client.add('add_key2', 'v2', 2)
|
12
12
|
|
13
13
|
@client.set('set_key1', 'v1', 0)
|
14
|
-
@client.set('set_key2', 'v2',
|
14
|
+
@client.set('set_key2', 'v2', 2)
|
15
15
|
|
16
16
|
@client.fetch('fetch_key1', 0) { 'v1' }
|
17
|
-
@client.fetch('fetch_key2',
|
17
|
+
@client.fetch('fetch_key2', 2) { 'v2' }
|
18
18
|
|
19
19
|
@client.add('cas_key1', 'v0')
|
20
20
|
@client.add('cas_key2', 'v0')
|
21
21
|
@client.cas('cas_key1', 0) { 'v1' }
|
22
|
-
@client.cas('cas_key2',
|
22
|
+
@client.cas('cas_key2', 2) { 'v2' }
|
23
23
|
|
24
24
|
@client.add('replace_key1', 'v0')
|
25
25
|
@client.add('replace_key2', 'v0')
|
26
26
|
@client.replace('replace_key1', 'v1', 0)
|
27
|
-
@client.replace('replace_key2', 'v2',
|
27
|
+
@client.replace('replace_key2', 'v2', 2)
|
28
28
|
|
29
|
-
@client.add('touch_key1', 'v1',
|
29
|
+
@client.add('touch_key1', 'v1', 2)
|
30
30
|
|
31
|
-
sleep 0.
|
32
|
-
@client.touch('touch_key1')
|
31
|
+
sleep 0.1
|
33
32
|
|
34
|
-
|
33
|
+
assert_equal 'v2', @client.get('add_key2')
|
34
|
+
assert_equal 'v2', @client.get('set_key2')
|
35
|
+
assert_equal 'v2', @client.get('fetch_key2')
|
36
|
+
assert_equal 'v2', @client.get('cas_key2')
|
37
|
+
assert_equal 'v2', @client.get('replace_key2')
|
38
|
+
|
39
|
+
assert @client.touch('touch_key1')
|
40
|
+
|
41
|
+
sleep 2
|
35
42
|
assert_equal 'v1', @client['touch_key1']
|
36
43
|
|
37
44
|
assert_equal 'v1', @client.get('add_key1')
|
@@ -132,6 +139,14 @@ class SpymemcachedTest < Test::Unit::TestCase
|
|
132
139
|
assert_nil @ns_client['key2']
|
133
140
|
end
|
134
141
|
|
142
|
+
def test_lambda_as_namespace
|
143
|
+
@ns_client = Spymemcached.new('localhost:11211', :namespace => lambda { 'ns' })
|
144
|
+
@ns_client['key'] = 'value'
|
145
|
+
assert_equal 'value', @client['ns:key']
|
146
|
+
|
147
|
+
assert_equal({'key' => "value"}, @ns_client.get_multi('key'))
|
148
|
+
end
|
149
|
+
|
135
150
|
def test_stats
|
136
151
|
stats = @client.stats
|
137
152
|
assert_equal(Hash, stats.class)
|