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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2041c63625bc2d15329384c3fcfc124d2c4f3e3
4
- data.tar.gz: dd2a6e89826d7fea2d48c802cc60eda42b72463f
3
+ metadata.gz: bdb378d078ec5deb37b38320e38e1a0961c979a4
4
+ data.tar.gz: 380044da20a32a1211d5fba6b6aa3b7cf239703f
5
5
  SHA512:
6
- metadata.gz: 7725d53c5682dcc8b321f7799a33738310425132f60e68e5d9b00af42dacd8d382a5730bd83a5bc921a5b7529733585b4b59471722ccba8c3bec266878cf6898
7
- data.tar.gz: fd482a06a00659cfe2f59965695d542c5ee00cb74bb5494dc1027190e00a397ffbf221df3c5f9286d0e64b3eccbdd9e98f7e03c615553cd158e6fe95825aedcd
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
- @options[:namespace] ? "#{@options[:namespace]}:#{key}" : key
130
+ return key unless namespace
131
+ "#{namespace.call}:#{key}"
128
132
  end
129
133
 
130
134
  def unns(k)
131
- return k unless @options[:namespace]
132
- @ns_size ||= @options[:namespace].size + 1
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
@@ -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', 1)
11
+ @client.add('add_key2', 'v2', 2)
12
12
 
13
13
  @client.set('set_key1', 'v1', 0)
14
- @client.set('set_key2', 'v2', 1)
14
+ @client.set('set_key2', 'v2', 2)
15
15
 
16
16
  @client.fetch('fetch_key1', 0) { 'v1' }
17
- @client.fetch('fetch_key2', 1) { 'v2' }
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', 1) { 'v2' }
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', 1)
27
+ @client.replace('replace_key2', 'v2', 2)
28
28
 
29
- @client.add('touch_key1', 'v1', 1)
29
+ @client.add('touch_key1', 'v1', 2)
30
30
 
31
- sleep 0.5
32
- @client.touch('touch_key1')
31
+ sleep 0.1
33
32
 
34
- sleep 0.7
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spymemcached.jruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: universal-java-1.7
6
6
  authors:
7
7
  - Xiao Li