spymemcached.jruby 1.0.10-java → 1.0.11-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -16
- data/lib/spymemcached.rb +16 -14
- data/lib/spymemcached/rails23.rb +8 -4
- data/lib/spymemcached_adapter.jar +0 -0
- data/test/m.png +0 -0
- data/test/spymemcached_binary_protocol_test.rb +10 -6
- data/test/spymemcached_plain_protocol_test.rb +6 -6
- data/test/spymemcached_rails23_test.rb +4 -4
- data/test/spymemcached_test.rb +12 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06b5837f82e9d9ac407c2c5fe0bb5ee5daf8a3b0
|
4
|
+
data.tar.gz: 3edb71d0e84508cb9447ea68a4cf1a8f9bb44f27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e48238823c00d32dd5ba47ed7efc66b9c101a202f26132a9c2d5fa8eb4f0cf0376b8333d49a4b64ae03aab85189511583c9ab01ca4b74dc977567a894e598d86
|
7
|
+
data.tar.gz: be02cf6b0e7c8959424e73b777d5b0bfabf867feea3640fcf6dd7980143d67891e67187c337a2de0bab78148efac7fcedb8fe16b375665012e91d632aee58cfd
|
data/README.md
CHANGED
@@ -22,9 +22,10 @@ Setup multiple servers with options
|
|
22
22
|
|
23
23
|
Valid +options+ are:
|
24
24
|
|
25
|
-
[:namespace]
|
26
|
-
[:timeout]
|
27
|
-
[:binary]
|
25
|
+
[:namespace] Prepends this value to all keys added or retrieved.
|
26
|
+
[:timeout] Time to use as the socket read timeout, seconds. Defaults to 0.5 sec.
|
27
|
+
[:binary] Talks binary protocol with Memcached server. Default to true.
|
28
|
+
[:should_optimize] If true, Spymemcached low-level optimization is in effect. Default to false.
|
28
29
|
|
29
30
|
### Rails 4
|
30
31
|
|
@@ -40,19 +41,6 @@ Use [spymemcached_store](https://github.com/ThoughtWorksStudios/spymemcached_sto
|
|
40
41
|
require 'spymemcached'
|
41
42
|
ActionController::Base.cache_store = :mem_cache_store, Spymemcached.new(servers, options).rails23
|
42
43
|
|
43
|
-
## Compatibility
|
44
|
-
|
45
|
-
The most important different between spymemcached.jruby and other non spymemcached backended memcache client is the support of option :raw.
|
46
|
-
|
47
|
-
As Spymemcached provides mechanism to encode and decode cache data, spymemcached.jruby does marshal dump & load for Ruby object in Java except Ruby string and integer.
|
48
|
-
|
49
|
-
Any Ruby String or Integer type cache data will be directly converted to Java String or Integer.
|
50
|
-
|
51
|
-
Hence we don't consider :raw option in spymemcached.jruby.
|
52
|
-
|
53
|
-
However, Rails cache store supports :raw option too when doing read and write on local cache.
|
54
|
-
This behaviour is kept as I'm not sure what to do with it. I'm happy to fix it if you found anything wrong with it.
|
55
|
-
|
56
44
|
## Default behaviors
|
57
45
|
|
58
46
|
Spymemcached.jruby applies:
|
data/lib/spymemcached.rb
CHANGED
@@ -14,7 +14,8 @@ class Spymemcached
|
|
14
14
|
# default options for client
|
15
15
|
DEFAULT_OPTIONS = {
|
16
16
|
:timeout => 0.5, # second
|
17
|
-
:binary => true
|
17
|
+
:binary => true,
|
18
|
+
:should_optimize => false
|
18
19
|
}
|
19
20
|
|
20
21
|
# Accepts a list of +servers+ and a list of +options+.
|
@@ -26,9 +27,10 @@ class Spymemcached
|
|
26
27
|
#
|
27
28
|
# Valid +options+ are:
|
28
29
|
#
|
29
|
-
# [:namespace]
|
30
|
-
# [:timeout]
|
31
|
-
# [:binary]
|
30
|
+
# [:namespace] Prepends this value to all keys added or retrieved. Default to nil.
|
31
|
+
# [:timeout] Time to use as the socket read timeout, seconds. Default to 0.5 sec.
|
32
|
+
# [:binary] Talks binary protocol with Memcached server. Default to true.
|
33
|
+
# [:should_optimize] If true, Spymemcached low-level optimization is in effect. Default to false.
|
32
34
|
#
|
33
35
|
# Logger: see Spymemcached for how to turn on detail log
|
34
36
|
#
|
@@ -61,21 +63,21 @@ class Spymemcached
|
|
61
63
|
Hash[@client.get_multi(key_map.keys).map {|k, v| [key_map[k], v]}]
|
62
64
|
end
|
63
65
|
|
64
|
-
def add(key, value, ttl=0)
|
65
|
-
@client.add(encode(key), value, ttl)
|
66
|
+
def add(key, value, ttl=0, opts={})
|
67
|
+
@client.add(encode(key), value, ttl, opts[:raw])
|
66
68
|
end
|
67
69
|
|
68
|
-
def set(key, value, ttl=0)
|
69
|
-
@client.set(encode(key), value, ttl)
|
70
|
+
def set(key, value, ttl=0, opts={})
|
71
|
+
@client.set(encode(key), value, ttl, opts[:raw])
|
70
72
|
end
|
71
73
|
alias :[]= :set
|
72
74
|
|
73
|
-
def cas(key, ttl=0, &block)
|
74
|
-
@client.cas(encode(key), ttl, &block)
|
75
|
+
def cas(key, ttl=0, opts={}, &block)
|
76
|
+
@client.cas(encode(key), ttl, opts[:raw], &block)
|
75
77
|
end
|
76
78
|
|
77
|
-
def replace(key, value, ttl=0)
|
78
|
-
@client.replace(encode(key), value, ttl)
|
79
|
+
def replace(key, value, ttl=0, opts={})
|
80
|
+
@client.replace(encode(key), value, ttl, opts[:raw])
|
79
81
|
end
|
80
82
|
|
81
83
|
def delete(key)
|
@@ -91,11 +93,11 @@ class Spymemcached
|
|
91
93
|
end
|
92
94
|
|
93
95
|
def append(key, value)
|
94
|
-
@client.append(encode(key), value)
|
96
|
+
@client.append(encode(key), value.to_s)
|
95
97
|
end
|
96
98
|
|
97
99
|
def prepend(key, value)
|
98
|
-
@client.prepend(encode(key), value)
|
100
|
+
@client.prepend(encode(key), value.to_s)
|
99
101
|
end
|
100
102
|
|
101
103
|
def touch(key, ttl=0)
|
data/lib/spymemcached/rails23.rb
CHANGED
@@ -25,12 +25,12 @@ class Spymemcached
|
|
25
25
|
op(:get, key)
|
26
26
|
end
|
27
27
|
|
28
|
-
def add(key, value, ttl=0,
|
29
|
-
op(:add, key, value, ttl) ? Response::STORED : Response::NOT_STORED
|
28
|
+
def add(key, value, ttl=0, raw=false)
|
29
|
+
op(:add, key, value, ttl, opts(raw)) ? Response::STORED : Response::NOT_STORED
|
30
30
|
end
|
31
31
|
|
32
|
-
def set(key, value, ttl=0,
|
33
|
-
op(:set, key, value, ttl) ? Response::STORED : Response::NOT_STORED
|
32
|
+
def set(key, value, ttl=0, raw=false)
|
33
|
+
op(:set, key, value, ttl, opts(raw)) ? Response::STORED : Response::NOT_STORED
|
34
34
|
end
|
35
35
|
|
36
36
|
def delete(key, *args)
|
@@ -54,6 +54,10 @@ class Spymemcached
|
|
54
54
|
end
|
55
55
|
|
56
56
|
private
|
57
|
+
def opts(raw)
|
58
|
+
raw.is_a?(Hash) ? raw : {:raw => raw}
|
59
|
+
end
|
60
|
+
|
57
61
|
def op(name, *args, &block)
|
58
62
|
@client.send(name, *args, &block)
|
59
63
|
rescue Spymemcached::Error => e
|
Binary file
|
data/test/m.png
ADDED
Binary file
|
@@ -39,7 +39,7 @@ class SpymemcachedBinaryProtocolTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_incr_and_decr
|
42
|
-
@client.add('key', '0')
|
42
|
+
@client.add('key', '0', 0, :raw => true)
|
43
43
|
assert_equal 0, @client.incr('key', 0)
|
44
44
|
@client.incr('key')
|
45
45
|
assert_equal 1, @client.incr('key', 0)
|
@@ -47,16 +47,16 @@ class SpymemcachedBinaryProtocolTest < Test::Unit::TestCase
|
|
47
47
|
assert_equal 6, @client.incr('key', 0)
|
48
48
|
assert_equal '6', @client.get('key')
|
49
49
|
|
50
|
-
@client.set('key', '6')
|
50
|
+
@client.set('key', '6', 0, :raw => true)
|
51
51
|
@client.decr('key')
|
52
52
|
assert_equal 5, @client.decr('key', 0)
|
53
53
|
@client.decr('key', 3)
|
54
54
|
assert_equal 2, @client.decr('key', 0)
|
55
55
|
|
56
|
-
@client.replace('key', '10')
|
56
|
+
@client.replace('key', '10', 0, :raw => true)
|
57
57
|
assert_equal 11, @client.incr('key')
|
58
58
|
|
59
|
-
@client.cas('key') { '7' }
|
59
|
+
@client.cas('key', 0, :raw => true) { '7' }
|
60
60
|
assert_equal 8, @client.incr('key')
|
61
61
|
|
62
62
|
assert_equal 100, @client.incr('incr_key', 1, 0, 100)
|
@@ -115,14 +115,18 @@ class SpymemcachedBinaryProtocolTest < Test::Unit::TestCase
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def test_append_string
|
118
|
-
@client
|
118
|
+
@client.set('k1', 'v', 0, :raw => true)
|
119
119
|
assert @client.append('k1', '1')
|
120
120
|
assert_equal 'v1', @client['k1']
|
121
|
+
assert @client.append('k1', 2)
|
122
|
+
assert_equal 'v12', @client['k1']
|
121
123
|
end
|
122
124
|
|
123
125
|
def test_prepend_string
|
124
|
-
@client
|
126
|
+
@client.set('k1', 'v', 0, :raw => true)
|
125
127
|
assert @client.prepend('k1', '1')
|
126
128
|
assert_equal '1v', @client['k1']
|
129
|
+
assert @client.prepend('k1', 2)
|
130
|
+
assert_equal '21v', @client['k1']
|
127
131
|
end
|
128
132
|
end
|
@@ -39,7 +39,7 @@ class SpymemcachedPlainProtocolTest < Test::Unit::TestCase
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_incr_and_decr
|
42
|
-
@client.add('key', '0')
|
42
|
+
@client.add('key', '0', 0, :raw => true)
|
43
43
|
assert_equal 0, @client.incr('key', 0)
|
44
44
|
@client.incr('key')
|
45
45
|
assert_equal 1, @client.incr('key', 0)
|
@@ -47,16 +47,16 @@ class SpymemcachedPlainProtocolTest < Test::Unit::TestCase
|
|
47
47
|
assert_equal 6, @client.incr('key', 0)
|
48
48
|
assert_equal '6', @client.get('key')
|
49
49
|
|
50
|
-
@client.set('key', '6')
|
50
|
+
@client.set('key', '6', 0, :raw => true)
|
51
51
|
@client.decr('key')
|
52
52
|
assert_equal 5, @client.decr('key', 0)
|
53
53
|
@client.decr('key', 3)
|
54
54
|
assert_equal 2, @client.decr('key', 0)
|
55
55
|
|
56
|
-
@client.replace('key', '10')
|
56
|
+
@client.replace('key', '10', 0, :raw => true)
|
57
57
|
assert_equal 11, @client.incr('key')
|
58
58
|
|
59
|
-
@client.cas('key') { '7' }
|
59
|
+
@client.cas('key', 0, :raw => true) { '7' }
|
60
60
|
assert_equal 8, @client.incr('key')
|
61
61
|
|
62
62
|
assert_equal 100, @client.incr('incr_key', 1, 0, 100)
|
@@ -115,13 +115,13 @@ class SpymemcachedPlainProtocolTest < Test::Unit::TestCase
|
|
115
115
|
end
|
116
116
|
|
117
117
|
def test_append_string
|
118
|
-
@client
|
118
|
+
@client.set('k1', 'v', 0, :raw => true)
|
119
119
|
assert @client.append('k1', '1')
|
120
120
|
assert_equal 'v1', @client['k1']
|
121
121
|
end
|
122
122
|
|
123
123
|
def test_prepend_string
|
124
|
-
@client
|
124
|
+
@client.set('k1', 'v', 0, :raw => true)
|
125
125
|
assert @client.prepend('k1', '1')
|
126
126
|
assert_equal '1v', @client['k1']
|
127
127
|
end
|
@@ -14,8 +14,8 @@ class SpymemcachedRails23Test < Test::Unit::TestCase
|
|
14
14
|
assert_equal response::DELETED, @client.delete('key')
|
15
15
|
assert_equal response::NOT_FOUND, @client.delete('key2')
|
16
16
|
|
17
|
-
@client.set("key1", '0')
|
18
|
-
@client.set("key2", '1')
|
17
|
+
@client.set("key1", '0', 0, :raw => true)
|
18
|
+
@client.set("key2", '1', 0, :raw => true)
|
19
19
|
assert_equal({"key1" => '0', 'key2' => '1'}, @client.get_multi('key1', 'key2'))
|
20
20
|
|
21
21
|
assert_equal 1, @client.incr('key1', 1, ttl=0)
|
@@ -25,8 +25,8 @@ class SpymemcachedRails23Test < Test::Unit::TestCase
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_rails3_api_compatible
|
28
|
-
@client.set("key1", '0')
|
29
|
-
@client.set("key2", '1')
|
28
|
+
@client.set("key1", '0', 0, :raw => true)
|
29
|
+
@client.set("key2", '1', 0, :raw => true)
|
30
30
|
assert_equal({"key1" => '0', 'key2' => '1'}, @client.get_multi(['key1', 'key2'], :raw => true))
|
31
31
|
end
|
32
32
|
|
data/test/spymemcached_test.rb
CHANGED
@@ -131,13 +131,14 @@ class SpymemcachedTest < Test::Unit::TestCase
|
|
131
131
|
assert_equal 'v3', @client['key3']
|
132
132
|
assert_nil @ns_client['key3']
|
133
133
|
|
134
|
-
@ns_client.
|
135
|
-
|
134
|
+
@ns_client.add('key5', 'v5', 0, :raw => true)
|
135
|
+
@ns_client.append('key5', '4')
|
136
|
+
assert_equal 'v54', @ns_client.get('key5')
|
136
137
|
|
137
|
-
@ns_client.prepend('
|
138
|
-
assert_equal '
|
138
|
+
@ns_client.prepend('key5', '4')
|
139
|
+
assert_equal '4v54', @ns_client.get('key5')
|
139
140
|
|
140
|
-
@ns_client
|
141
|
+
@ns_client.set('key2', '1', 0, :raw => true)
|
141
142
|
assert_equal 2, @ns_client.incr('key2')
|
142
143
|
assert_equal 1, @ns_client.decr('key2')
|
143
144
|
|
@@ -201,4 +202,10 @@ class SpymemcachedTest < Test::Unit::TestCase
|
|
201
202
|
assert client.set('key', 'value')
|
202
203
|
assert_equal 'value', client.get('key')
|
203
204
|
end
|
205
|
+
|
206
|
+
def test_get_set_binary_string_data
|
207
|
+
data = File.read(File.join(File.dirname(__FILE__), "m.png"))
|
208
|
+
@client.add('k', data)
|
209
|
+
assert_equal(data, @client.get('k'))
|
210
|
+
end
|
204
211
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spymemcached.jruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Xiao Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/spymemcached.rb
|
72
72
|
- lib/spymemcached_adapter.jar
|
73
73
|
- lib/spymemcached/rails23.rb
|
74
|
+
- test/m.png
|
74
75
|
- test/memcache.rb
|
75
76
|
- test/spymemcached_binary_protocol_test.rb
|
76
77
|
- test/spymemcached_plain_protocol_test.rb
|