jruby-memcache-client 1.7.0 → 1.7.1
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.
- data/Gemfile +7 -0
- data/Gemfile.lock +44 -0
- data/README +5 -0
- data/Rakefile +5 -2
- data/VERSION.yml +3 -2
- data/jruby-memcache-client.gemspec +35 -24
- data/lib/java/java_memcached-release_2.5.1.jar +0 -0
- data/lib/memcache.rb +56 -24
- data/spec/jruby_memcache_spec.rb +233 -229
- metadata +127 -40
- data/.gitignore +0 -7
- data/lib/java/memcached-dev_2.0.2.jar +0 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.0.8)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.8.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rdoc
|
12
|
+
json (1.7.6)
|
13
|
+
json (1.7.6-java)
|
14
|
+
method_source (0.8.1)
|
15
|
+
pry (0.9.11.4-java)
|
16
|
+
coderay (~> 1.0.5)
|
17
|
+
method_source (~> 0.8)
|
18
|
+
slop (~> 3.4)
|
19
|
+
spoon (~> 0.0)
|
20
|
+
pry-nav (0.2.3)
|
21
|
+
pry (~> 0.9.10)
|
22
|
+
rake (10.0.3)
|
23
|
+
rdoc (3.12)
|
24
|
+
json (~> 1.4)
|
25
|
+
rspec (2.12.0)
|
26
|
+
rspec-core (~> 2.12.0)
|
27
|
+
rspec-expectations (~> 2.12.0)
|
28
|
+
rspec-mocks (~> 2.12.0)
|
29
|
+
rspec-core (2.12.2)
|
30
|
+
rspec-expectations (2.12.1)
|
31
|
+
diff-lcs (~> 1.1.3)
|
32
|
+
rspec-mocks (2.12.1)
|
33
|
+
slop (3.4.3)
|
34
|
+
spoon (0.0.1)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
java
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
jeweler
|
41
|
+
pry
|
42
|
+
pry-nav
|
43
|
+
rake
|
44
|
+
rspec
|
data/README
CHANGED
@@ -26,6 +26,11 @@ You will then be able to install the JRuby Memcache Client gem:
|
|
26
26
|
|
27
27
|
jruby -S gem install jruby-memcache-client
|
28
28
|
|
29
|
+
Java Requirements
|
30
|
+
-----------------
|
31
|
+
|
32
|
+
The underlying library used for this project was compiled using Java 6. You will not be able to run this gem under Java 5 out of the box. You can however clone http://github.com/gwhalin/Memcached-Java-Client and attempt to build it under Java 5 if you must. (You really should consider upgrading to Java 6 since Oracle no longer supports Java 5.)
|
33
|
+
|
29
34
|
Replacing Rail's MemCache Client
|
30
35
|
--------------------------------
|
31
36
|
|
data/Rakefile
CHANGED
@@ -15,13 +15,16 @@ end
|
|
15
15
|
|
16
16
|
if RUBY_PLATFORM =~ /java/i
|
17
17
|
begin
|
18
|
-
require '
|
18
|
+
require 'rspec/core/rake_task'
|
19
19
|
|
20
20
|
task :default => :spec
|
21
21
|
|
22
22
|
desc "Run the specs for the jruby-memcache-client gem"
|
23
|
-
|
23
|
+
RSpec::Core::RakeTask.new(:spec)
|
24
24
|
rescue LoadError
|
25
|
+
|
26
|
+
require 'pry'; binding.pry
|
27
|
+
|
25
28
|
puts "You must have rspec installed in order to run the tests."
|
26
29
|
end
|
27
30
|
else
|
data/VERSION.yml
CHANGED
@@ -1,48 +1,59 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.7.
|
7
|
+
s.name = "jruby-memcache-client"
|
8
|
+
s.version = "1.7.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Abhi Yerra", "Ikai Lan", "Frederic Jean", "Lennon Day-Reynolds", "slyphon", "Brayn Helmkamp", "Travis Tilley"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2013-01-25"
|
13
|
+
s.description = "A drop in replacement for Ruby's memcache-client."
|
14
|
+
s.email = "fred@fredjean.net"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
"
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
]
|
29
|
-
s.homepage = %q{http://github.com/ikai/jruby-memcache-client}
|
30
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
31
|
-
s.require_paths = ["lib"]
|
32
|
-
s.rubygems_version = %q{1.3.5}
|
33
|
-
s.summary = %q{A drop in replacement for Ruby's memcache-client.}
|
34
|
-
s.test_files = [
|
19
|
+
"Gemfile",
|
20
|
+
"Gemfile.lock",
|
21
|
+
"MIT-LICENSE",
|
22
|
+
"README",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"jruby-memcache-client.gemspec",
|
26
|
+
"lib/java/java_memcached-release_2.5.1.jar",
|
27
|
+
"lib/memcache.rb",
|
35
28
|
"spec/jruby_memcache_spec.rb"
|
36
29
|
]
|
30
|
+
s.homepage = "http://github.com/ikai/jruby-memcache-client"
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = "1.8.24"
|
33
|
+
s.summary = "A drop in replacement for Ruby's memcache-client."
|
37
34
|
|
38
35
|
if s.respond_to? :specification_version then
|
39
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
36
|
s.specification_version = 3
|
41
37
|
|
42
|
-
if Gem::Version.new(Gem::
|
38
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
39
|
+
s.add_runtime_dependency(%q<jeweler>, [">= 0"])
|
40
|
+
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
41
|
+
s.add_runtime_dependency(%q<rspec>, [">= 0"])
|
42
|
+
s.add_runtime_dependency(%q<pry>, [">= 0"])
|
43
|
+
s.add_runtime_dependency(%q<pry-nav>, [">= 0"])
|
43
44
|
else
|
45
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
46
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
47
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
48
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
49
|
+
s.add_dependency(%q<pry-nav>, [">= 0"])
|
44
50
|
end
|
45
51
|
else
|
52
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
53
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
54
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
55
|
+
s.add_dependency(%q<pry>, [">= 0"])
|
56
|
+
s.add_dependency(%q<pry-nav>, [">= 0"])
|
46
57
|
end
|
47
58
|
end
|
48
59
|
|
Binary file
|
data/lib/memcache.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'java'
|
2
2
|
require 'base64'
|
3
3
|
|
4
|
-
require File.dirname(__FILE__) + '/java/
|
4
|
+
require File.dirname(__FILE__) + '/java/java_memcached-release_2.5.1.jar'
|
5
5
|
|
6
6
|
class MemCache
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
java_import 'com.danga.MemCached.MemCachedClient'
|
8
|
+
java_import 'com.danga.MemCached.SockIOPool'
|
9
|
+
java_import 'com.danga.MemCached.Logger'
|
10
10
|
|
11
|
-
VERSION = '1.7.
|
11
|
+
VERSION = '1.7.1'
|
12
12
|
|
13
13
|
##
|
14
14
|
# Default options for the cache object.
|
@@ -85,13 +85,22 @@ class MemCache
|
|
85
85
|
raise ArgumentError, "wrong number of arguments (#{args.length} for 2)"
|
86
86
|
end
|
87
87
|
|
88
|
+
# Normalizing the server(s) so they all have a port number.
|
89
|
+
|
90
|
+
@servers = @servers.map do |server|
|
91
|
+
server =~ /(.+):(\d+)/ ? server : "#{server}:#{DEFAULT_PORT}"
|
92
|
+
end
|
93
|
+
|
94
|
+
Logger.getLogger('com.meetup.memcached.MemcachedClient').setLevel(opts[:log_level])
|
95
|
+
Logger.getLogger('com.meetup.memcached.SockIOPool').setLevel(opts[:log_level])
|
96
|
+
|
88
97
|
opts = DEFAULT_OPTIONS.merge opts
|
89
98
|
|
90
99
|
@namespace = opts[:namespace] || opts["namespace"]
|
91
100
|
@pool_name = opts[:pool_name] || opts["pool_name"]
|
92
101
|
@readonly = opts[:readonly] || opts["readonly"]
|
93
102
|
|
94
|
-
@client =
|
103
|
+
@client = MemCachedClient.new(@pool_name)
|
95
104
|
|
96
105
|
@client.error_handler = opts[:error_handler] if opts[:error_handler]
|
97
106
|
@client.primitiveAsString = true
|
@@ -119,17 +128,25 @@ class MemCache
|
|
119
128
|
@pool.aliveCheck = opts[:pool_use_alive]
|
120
129
|
@pool.nagle = opts[:pool_use_nagle]
|
121
130
|
|
131
|
+
# public static final int NATIVE_HASH = 0;
|
132
|
+
# // native String.hashCode();
|
133
|
+
# public static final int OLD_COMPAT_HASH = 1;
|
134
|
+
# // original compatibility hashing algorithm (works with other clients)
|
135
|
+
# public static final int NEW_COMPAT_HASH = 2;
|
136
|
+
# // new CRC32 based compatibility hashing algorithm (works with other clients)
|
137
|
+
# public static final int CONSISTENT_HASH = 3;
|
138
|
+
# // MD5 Based -- Stops thrashing when a server added or removed
|
139
|
+
@pool.hashingAlg = opts[:pool_hashing_algorithm]
|
140
|
+
|
122
141
|
# __method methods have been removed in jruby 1.5
|
123
|
-
|
142
|
+
@pool.java_send :initialize rescue @pool.initialize__method
|
124
143
|
end
|
125
144
|
|
126
|
-
Logger.getLogger('com.meetup.memcached.MemcachedClient').setLevel(opts[:log_level])
|
127
|
-
Logger.getLogger('com.meetup.memcached.SockIOPool').setLevel(opts[:log_level])
|
128
145
|
end
|
129
146
|
|
130
147
|
def reset
|
131
148
|
@pool.shut_down
|
132
|
-
|
149
|
+
@pool.java_send :initialize rescue @pool.initialize__method
|
133
150
|
end
|
134
151
|
|
135
152
|
##
|
@@ -163,9 +180,17 @@ class MemCache
|
|
163
180
|
value = @client.get(make_cache_key(key))
|
164
181
|
return nil if value.nil?
|
165
182
|
unless raw
|
166
|
-
|
167
|
-
|
168
|
-
|
183
|
+
begin
|
184
|
+
marshal_bytes = java.lang.String.new(value).getBytes(MARSHALLING_CHARSET)
|
185
|
+
decoded = Base64.decode64(String.from_java_bytes(marshal_bytes))
|
186
|
+
value = Marshal.load(decoded)
|
187
|
+
rescue
|
188
|
+
value = case value
|
189
|
+
when /^\d+\.\d+$/ then value.to_f
|
190
|
+
when /^\d+$/ then value.to_i
|
191
|
+
else value
|
192
|
+
end
|
193
|
+
end
|
169
194
|
end
|
170
195
|
value
|
171
196
|
end
|
@@ -183,9 +208,17 @@ class MemCache
|
|
183
208
|
k,v = kv
|
184
209
|
next if v.nil?
|
185
210
|
unless raw
|
186
|
-
|
187
|
-
|
188
|
-
|
211
|
+
begin
|
212
|
+
marshal_bytes = java.lang.String.new(v).getBytes(MARSHALLING_CHARSET)
|
213
|
+
decoded = Base64.decode64(String.from_java_bytes(marshal_bytes))
|
214
|
+
v = Marshal.load(decoded)
|
215
|
+
rescue
|
216
|
+
v = case v
|
217
|
+
when /^\d+\.\d+$/ then v.to_f
|
218
|
+
when /^\d+$/ then v.to_i
|
219
|
+
else v
|
220
|
+
end
|
221
|
+
end
|
189
222
|
end
|
190
223
|
values[k] = v
|
191
224
|
}
|
@@ -250,20 +283,18 @@ class MemCache
|
|
250
283
|
# Increments the value associated with the key by a certain amount.
|
251
284
|
def incr(key, amount = 1)
|
252
285
|
raise MemCacheError, "Update of readonly cache" if @readonly
|
253
|
-
value =
|
254
|
-
value
|
255
|
-
|
256
|
-
value
|
286
|
+
value = @client.incr(make_cache_key(key), amount)
|
287
|
+
return nil if value == "NOT_FOUND\r\n"
|
288
|
+
return value.to_i
|
257
289
|
end
|
258
290
|
|
259
291
|
##
|
260
292
|
# Decrements the value associated with the key by a certain amount.
|
261
293
|
def decr(key, amount = 1)
|
262
294
|
raise MemCacheError, "Update of readonly cache" if @readonly
|
263
|
-
value =
|
264
|
-
value
|
265
|
-
|
266
|
-
value
|
295
|
+
value = @client.decr(make_cache_key(key),amount)
|
296
|
+
return nil if value == "NOT_FOUND\r\n"
|
297
|
+
return value.to_i
|
267
298
|
end
|
268
299
|
|
269
300
|
##
|
@@ -305,6 +336,7 @@ class MemCache
|
|
305
336
|
end
|
306
337
|
|
307
338
|
def marshal_value(value)
|
339
|
+
return value if value.kind_of?(Numeric)
|
308
340
|
encoded = Base64.encode64(Marshal.dump(value))
|
309
341
|
marshal_bytes = encoded.to_java_bytes
|
310
342
|
java.lang.String.new(marshal_bytes, MARSHALLING_CHARSET)
|
data/spec/jruby_memcache_spec.rb
CHANGED
@@ -2,266 +2,270 @@ require 'java'
|
|
2
2
|
require File.dirname(__FILE__) + '/../lib/memcache'
|
3
3
|
|
4
4
|
describe MemCache do
|
5
|
-
before :all do
|
6
|
-
@server = "127.0.0.1:11211"
|
7
|
-
@client = MemCache.new @server
|
8
|
-
end
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
@client.flush_all
|
12
|
-
end
|
13
|
-
after :each do
|
14
|
-
@client.flush_all
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should return nil for a non-existent key" do
|
18
|
-
@client.get('non-existent-key').should be_nil
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "setting servers" do
|
22
|
-
it "should work if the instance is created with a single String argument" do
|
23
|
-
@client = MemCache.new @server
|
24
|
-
@client.servers.should == [@server]
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should work if the instance is created with an Array" do
|
28
|
-
@client = MemCache.new [ @server ]
|
29
|
-
@client.servers.should == [ @server ]
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should work if the instance is created with a Hash" do
|
33
|
-
@client = MemCache.new [ @server ], :namespace => 'test'
|
34
|
-
@client.servers.should == [ @server ]
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should work with an explicit pool name" do
|
38
|
-
@client = MemCache.new([@server], :pool_name => 'new_pool')
|
39
|
-
@client.pool_name.should == 'new_pool'
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should work with an error handler" do
|
43
|
-
include_class 'com.meetup.memcached.MemcachedClient'
|
44
|
-
java_memcache_client = mock.as_null_object
|
45
|
-
MemcachedClient.stub!(:new => java_memcache_client)
|
46
|
-
error_handler = Object.new
|
47
|
-
java_memcache_client.should_receive(:error_handler=).with(error_handler)
|
48
|
-
@client = MemCache.new([@server], :error_handler => error_handler)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "namespacing" do
|
53
|
-
before(:each) do
|
54
|
-
@ns = 'namespace'
|
55
|
-
@nsclient = MemCache.new [ @server ] , :namespace => @ns
|
56
|
-
@nsclient.flush_all
|
57
|
-
@nsclient.set "test", 333, 0
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should set and get values transparently" do
|
61
|
-
@nsclient.get("test").to_i.should == 333
|
62
|
-
end
|
63
|
-
|
64
|
-
it "should set values to the given namespace" do
|
65
|
-
@client.get("#{@ns}:test").to_i.should == 333
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should not set a value without the given namespace" do
|
69
|
-
@client.get("test").to_i.should_not == 333
|
70
|
-
end
|
71
|
-
|
72
|
-
it "should delete values in the given namespace" do
|
73
|
-
@nsclient.delete "test"
|
74
|
-
@nsclient.get("test").should be_nil
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should increment in the given namespace" do
|
78
|
-
@nsclient.incr("test").to_i.should == 334
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should decrement values in the given namespace" do
|
82
|
-
@nsclient.decr("test").should == 332
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe "after setting a value to MemCache" do
|
87
|
-
before(:each) do
|
88
|
-
@client.set 'key', 'value'
|
89
|
-
end
|
90
|
-
|
91
|
-
it "should be able to retrieve the value" do
|
92
|
-
@client.get('key').should == 'value'
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should not be able to retrieve the value after deleting" do
|
96
|
-
@client.delete('key')
|
97
|
-
@client.get('key').should be_nil
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should not be able to retrieve the value after flushing everything" do
|
101
|
-
@client.flush_all
|
102
|
-
@client.get("key").should be_nil
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should work exactly the same if the []= operator were used" do
|
106
|
-
@client['key'] = 'val'
|
107
|
-
@client.get('key').should == 'val'
|
108
|
-
end
|
109
|
-
end
|
110
5
|
|
111
|
-
|
112
|
-
before :each do
|
113
|
-
@client['key'] = 'value'
|
114
|
-
end
|
6
|
+
hostname = `hostname`.strip
|
115
7
|
|
116
|
-
|
117
|
-
|
118
|
-
@
|
8
|
+
["127.0.0.1:11211", "127.0.0.1", "localhost:11211", "localhost"].each do |server|
|
9
|
+
before :all do
|
10
|
+
@server = server
|
11
|
+
@normalized_server = @server =~ /(.+):(\d+)/ ? @server : "#{@server}:11211"
|
119
12
|
end
|
120
13
|
|
121
|
-
it "should not replace values that are not in the cache." do
|
122
|
-
@client.replace('notthere', 'value').should be_false
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "using the Hash notation" do
|
127
14
|
before :each do
|
128
|
-
@client
|
129
|
-
|
130
|
-
|
131
|
-
it "should be able to retrieve the value using []" do
|
132
|
-
@client['key'].should == 'value'
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should be able to retrieve the value using get" do
|
136
|
-
@client.get('key').should == 'value'
|
15
|
+
@client = MemCache.new @server
|
16
|
+
@client.should_not be_nil
|
17
|
+
@client.flush_all
|
137
18
|
end
|
138
|
-
end
|
139
19
|
|
140
|
-
|
141
|
-
|
142
|
-
@client.stats.should be_instance_of(Hash)
|
20
|
+
after :each do
|
21
|
+
@client.flush_all
|
143
22
|
end
|
144
23
|
|
145
|
-
|
146
|
-
|
147
|
-
|
24
|
+
it "should return nil for a non-existent key" do
|
25
|
+
@client.get('non-existent-key').should be_nil
|
26
|
+
end
|
148
27
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
28
|
+
describe "setting servers" do
|
29
|
+
it "should work if the instance is created with a single String argument" do
|
30
|
+
@client = MemCache.new @server
|
31
|
+
@client.servers.should == [@normalized_server]
|
32
|
+
end
|
153
33
|
|
154
|
-
|
155
|
-
|
156
|
-
|
34
|
+
it "should work if the instance is created with an Array" do
|
35
|
+
@client = MemCache.new [ @server ]
|
36
|
+
@client.servers.should == [@normalized_server]
|
37
|
+
end
|
157
38
|
|
158
|
-
|
39
|
+
it "should work if the instance is created with a Hash" do
|
40
|
+
@client = MemCache.new [ @server ], :namespace => 'test'
|
41
|
+
@client.servers.should == [@normalized_server]
|
42
|
+
end
|
159
43
|
|
160
|
-
|
44
|
+
it "should work with an explicit pool name" do
|
45
|
+
@client = MemCache.new([@server], :pool_name => 'new_pool')
|
46
|
+
@client.pool_name.should == 'new_pool'
|
47
|
+
end
|
161
48
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
49
|
+
it "should work with an error handler" do
|
50
|
+
java_import 'com.danga.MemCached.MemCachedClient'
|
51
|
+
java_memcache_client = mock.as_null_object
|
52
|
+
MemCachedClient.stub!(:new => java_memcache_client)
|
53
|
+
error_handler = Object.new
|
54
|
+
java_memcache_client.should_receive(:error_handler=).with(error_handler)
|
55
|
+
@client = MemCache.new([@server], :error_handler => error_handler)
|
56
|
+
end
|
166
57
|
end
|
167
58
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
describe "#decr" do
|
59
|
+
describe "namespacing" do
|
60
|
+
before(:each) do
|
61
|
+
@ns = 'namespace'
|
62
|
+
@nsclient = MemCache.new [ @server ] , :namespace => @ns
|
63
|
+
@nsclient.flush_all
|
64
|
+
@nsclient.set "test", 333, 0
|
65
|
+
end
|
176
66
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
@client.get('decr').to_i.should == 99
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should decrement a value by a given second parameter" do
|
184
|
-
@client.set 'decr', 100, 0
|
185
|
-
@client.decr 'decr', 20
|
186
|
-
@client.get('decr').to_i.should == 80
|
187
|
-
end
|
188
|
-
end
|
67
|
+
it "should set and get values transparently" do
|
68
|
+
@nsclient.get("test").should == 333
|
69
|
+
end
|
189
70
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
@client.set('obj', obj)
|
194
|
-
@client.get('obj').should == obj
|
195
|
-
end
|
71
|
+
it "should set values to the given namespace" do
|
72
|
+
@nsclient.get("test").to_i.should == 333
|
73
|
+
end
|
196
74
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
@client.set('obj', obj)
|
201
|
-
@client.get('obj').should == obj
|
202
|
-
end
|
75
|
+
it "should not set a value without the given namespace" do
|
76
|
+
@client.get("test").to_i.should_not == 333
|
77
|
+
end
|
203
78
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
@client.get('blob').should == blob
|
209
|
-
end
|
210
|
-
end
|
79
|
+
it "should delete values in the given namespace" do
|
80
|
+
@nsclient.delete "test"
|
81
|
+
@nsclient.get("test").should be_nil
|
82
|
+
end
|
211
83
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
@client.get('key').should be_nil
|
216
|
-
end
|
84
|
+
it "should increment in the given namespace" do
|
85
|
+
@nsclient.incr("test").to_i.should == 334
|
86
|
+
end
|
217
87
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
sleep(3)
|
222
|
-
@client.get('key').should be_nil
|
88
|
+
it "should decrement values in the given namespace" do
|
89
|
+
@nsclient.decr("test").should == 332
|
90
|
+
end
|
223
91
|
end
|
224
|
-
end
|
225
92
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
@client.get_multi(%w/key key2/).should == {'key' => 'val', 'key2' => 'val2'}
|
231
|
-
end
|
93
|
+
describe "after setting a value to MemCache" do
|
94
|
+
before(:each) do
|
95
|
+
@client.set 'key', 'value'
|
96
|
+
end
|
232
97
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
@client.get_multi(%w/key key2 key3/).should == {'key' => 'val', 'key2' => 'val2'}
|
237
|
-
end
|
98
|
+
it "should be able to retrieve the value" do
|
99
|
+
@client.get('key').should == 'value'
|
100
|
+
end
|
238
101
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
end
|
244
|
-
end
|
102
|
+
it "should not be able to retrieve the value after deleting" do
|
103
|
+
@client.delete('key')
|
104
|
+
@client.get('key').should be_nil
|
105
|
+
end
|
245
106
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
@client.flush_all
|
251
|
-
end
|
107
|
+
it "should not be able to retrieve the value after flushing everything" do
|
108
|
+
@client.flush_all
|
109
|
+
@client.get("key").should be_nil
|
110
|
+
end
|
252
111
|
|
253
|
-
|
254
|
-
|
112
|
+
it "should work exactly the same if the []= operator were used" do
|
113
|
+
@client['key'] = 'val'
|
114
|
+
@client.get('key').should == 'val'
|
115
|
+
end
|
255
116
|
end
|
256
117
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
118
|
+
describe "replacing values from the cache." do
|
119
|
+
before :each do
|
120
|
+
@client['key'] = 'value'
|
121
|
+
end
|
261
122
|
|
262
|
-
|
263
|
-
|
264
|
-
|
123
|
+
it "should be able to replace the stored value." do
|
124
|
+
@client.replace('key', 'new value').should be_true
|
125
|
+
@client['key'].should == 'new value'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should not replace values that are not in the cache." do
|
129
|
+
@client.replace('notthere', 'value').should be_false
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "using the Hash notation" do
|
134
|
+
before :each do
|
135
|
+
@client['key'] = 'value'
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should be able to retrieve the value using []" do
|
139
|
+
@client['key'].should == 'value'
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should be able to retrieve the value using get" do
|
143
|
+
@client.get('key').should == 'value'
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "#stats" do
|
148
|
+
it "should return a hash" do
|
149
|
+
@client.stats.should be_instance_of(Hash)
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should return a float for rusage_system and rusage_user" do
|
153
|
+
@client.stats[@normalized_server]['rusage_system'].should be_instance_of(Float)
|
154
|
+
@client.stats[@normalized_server]['rusage_user'].should be_instance_of(Float)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should return a String for version" do
|
158
|
+
@client.stats[@normalized_server]['version'].should be_instance_of(String)
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "#incr" do
|
164
|
+
|
165
|
+
it "should increment a value by 1 without a second parameter" do
|
166
|
+
@client.set 'incr', 100, 0
|
167
|
+
@client.incr 'incr'
|
168
|
+
@client.get('incr').to_i.should == 101
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should increment a value by a given second parameter" do
|
172
|
+
@client.set 'incr', 100, 0
|
173
|
+
@client.incr 'incr', 20
|
174
|
+
@client.get('incr').to_i.should == 120
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "#decr" do
|
179
|
+
|
180
|
+
it "should decrement a value by 1 without a second parameter" do
|
181
|
+
@client.set 'decr', 100, 0
|
182
|
+
@client.decr 'decr'
|
183
|
+
@client.get('decr').to_i.should == 99
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should decrement a value by a given second parameter" do
|
187
|
+
@client.set 'decr', 100, 0
|
188
|
+
@client.decr 'decr', 20
|
189
|
+
@client.get('decr').to_i.should == 80
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "with Ruby Objects" do
|
194
|
+
it "should be able to transparently set and get equivalent Ruby objects" do
|
195
|
+
obj = { :test => :hi }
|
196
|
+
@client.set('obj', obj)
|
197
|
+
@client.get('obj').should == obj
|
198
|
+
end
|
199
|
+
|
200
|
+
it %[should work with those whose marshalled stream contains invalid UTF8 byte sequences] do
|
201
|
+
# this test fails w/o the Base64 encoding step
|
202
|
+
obj = { :foo => 900 }
|
203
|
+
@client.set('obj', obj)
|
204
|
+
@client.get('obj').should == obj
|
205
|
+
end
|
206
|
+
|
207
|
+
it %[should work with binary blobs] do
|
208
|
+
# this test fails w/o the Base64 encoding step
|
209
|
+
blob = "\377\330\377\340\000\020JFIF\000\001\001\000\000\001\000\001\000\000\377"
|
210
|
+
@client.set('blob', blob)
|
211
|
+
@client.get('blob').should == blob
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "using set with an expiration" do
|
216
|
+
it "should make a value unretrievable if the expiry is set to a negative value" do
|
217
|
+
@client.set('key', 'val', -1)
|
218
|
+
@client.get('key').should be_nil
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should make a value retrievable for only the amount of time if a value is given" do
|
222
|
+
@client.set('key', 'val', 2)
|
223
|
+
@client.get('key').should == 'val'
|
224
|
+
sleep(3)
|
225
|
+
@client.get('key').should be_nil
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe "#get_multi" do
|
230
|
+
it "should get 2 keys" do
|
231
|
+
@client.set('key', 'val')
|
232
|
+
@client.set('key2', 'val2')
|
233
|
+
@client.get_multi(%w/key key2/).should == {'key' => 'val', 'key2' => 'val2'}
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should ignore nil values" do
|
237
|
+
@client.set('key', 'val')
|
238
|
+
@client.set('key2', 'val2')
|
239
|
+
@client.get_multi(%w/key key2 key3/).should == {'key' => 'val', 'key2' => 'val2'}
|
240
|
+
end
|
241
|
+
|
242
|
+
it "should not marshall if requested" do
|
243
|
+
@client.set('key', 'val', 0, true)
|
244
|
+
@client.set('key2', 'val2', 0, true)
|
245
|
+
@client.get_multi(%w/key key2/, true).should == {'key' => 'val', 'key2' => 'val2'}
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe "aliveness of the MemCache server." do
|
250
|
+
before :each do
|
251
|
+
@servers = ["localhost:11211", "localhost:11212", {:pool_name => "test"}]
|
252
|
+
@client = MemCache.new @servers
|
253
|
+
@client.flush_all
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should report the client as being alive." do
|
257
|
+
@client.should be_alive
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should report localhost:11211 as being alive." do
|
261
|
+
servers = @client.servers
|
262
|
+
servers.first.should be_alive
|
263
|
+
end
|
264
|
+
|
265
|
+
it "should report localhost:11212 as not being alive." do
|
266
|
+
servers = @client.servers
|
267
|
+
servers.find {|s| s.to_s == "localhost:11212"}.should be_nil
|
268
|
+
end
|
265
269
|
end
|
266
270
|
end
|
267
271
|
end
|
metadata
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: jruby-memcache-client
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.7.1
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
+
authors:
|
7
8
|
- Abhi Yerra
|
8
9
|
- Ikai Lan
|
9
10
|
- Frederic Jean
|
@@ -11,59 +12,145 @@ authors:
|
|
11
12
|
- slyphon
|
12
13
|
- Brayn Helmkamp
|
13
14
|
- Travis Tilley
|
14
|
-
autorequire:
|
15
|
+
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: jeweler
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: !binary |-
|
27
|
+
MA==
|
28
|
+
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: !binary |-
|
34
|
+
MA==
|
35
|
+
none: false
|
36
|
+
prerelease: false
|
37
|
+
type: :runtime
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rake
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: !binary |-
|
45
|
+
MA==
|
46
|
+
none: false
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: !binary |-
|
52
|
+
MA==
|
53
|
+
none: false
|
54
|
+
prerelease: false
|
55
|
+
type: :runtime
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rspec
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: !binary |-
|
63
|
+
MA==
|
64
|
+
none: false
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: !binary |-
|
70
|
+
MA==
|
71
|
+
none: false
|
72
|
+
prerelease: false
|
73
|
+
type: :runtime
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: pry
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: !binary |-
|
81
|
+
MA==
|
82
|
+
none: false
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: !binary |-
|
88
|
+
MA==
|
89
|
+
none: false
|
90
|
+
prerelease: false
|
91
|
+
type: :runtime
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: pry-nav
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: !binary |-
|
99
|
+
MA==
|
100
|
+
none: false
|
101
|
+
requirement: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: !binary |-
|
106
|
+
MA==
|
107
|
+
none: false
|
108
|
+
prerelease: false
|
109
|
+
type: :runtime
|
22
110
|
description: A drop in replacement for Ruby's memcache-client.
|
23
111
|
email: fred@fredjean.net
|
24
112
|
executables: []
|
25
|
-
|
26
113
|
extensions: []
|
27
|
-
|
28
|
-
extra_rdoc_files:
|
114
|
+
extra_rdoc_files:
|
29
115
|
- README
|
30
|
-
files:
|
31
|
-
-
|
116
|
+
files:
|
117
|
+
- Gemfile
|
118
|
+
- Gemfile.lock
|
32
119
|
- MIT-LICENSE
|
33
120
|
- README
|
34
121
|
- Rakefile
|
35
122
|
- VERSION.yml
|
36
123
|
- jruby-memcache-client.gemspec
|
37
|
-
- lib/java/
|
124
|
+
- lib/java/java_memcached-release_2.5.1.jar
|
38
125
|
- lib/memcache.rb
|
39
126
|
- spec/jruby_memcache_spec.rb
|
40
|
-
has_rdoc: true
|
41
127
|
homepage: http://github.com/ikai/jruby-memcache-client
|
42
128
|
licenses: []
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
- --charset=UTF-8
|
47
|
-
require_paths:
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
48
132
|
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
hash: 2
|
140
|
+
version: !binary |-
|
141
|
+
MA==
|
142
|
+
none: false
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: !binary |-
|
148
|
+
MA==
|
149
|
+
none: false
|
61
150
|
requirements: []
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
signing_key:
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.8.24
|
153
|
+
signing_key:
|
66
154
|
specification_version: 3
|
67
155
|
summary: A drop in replacement for Ruby's memcache-client.
|
68
|
-
test_files:
|
69
|
-
- spec/jruby_memcache_spec.rb
|
156
|
+
test_files: []
|
data/.gitignore
DELETED
Binary file
|