jruby-memcached-thoughtworks 0.6.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.
- checksums.yaml +7 -0
- data/.gitignore +31 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +89 -0
- data/Gemfile +6 -0
- data/MIT-LICENSE +20 -0
- data/README.md +75 -0
- data/Rakefile +16 -0
- data/benchmark.rb +104 -0
- data/jruby_memcached.gemspec +21 -0
- data/lib/memcached.rb +12 -0
- data/lib/memcached/version.rb +3 -0
- data/pom.xml +69 -0
- data/spec/memcached_spec.rb +247 -0
- data/spec/rails_spec.rb +181 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/timeout_spec.rb +103 -0
- data/src/main/java/com/openfeint/memcached/Memcached.java +511 -0
- data/src/main/java/com/openfeint/memcached/MemcachedService.java +35 -0
- data/src/main/java/com/openfeint/memcached/Rails.java +237 -0
- data/src/main/java/com/openfeint/memcached/error/ATimeoutOccurred.java +7 -0
- data/src/main/java/com/openfeint/memcached/error/Error.java +31 -0
- data/src/main/java/com/openfeint/memcached/error/NotFound.java +7 -0
- data/src/main/java/com/openfeint/memcached/error/NotStored.java +7 -0
- data/src/main/java/com/openfeint/memcached/error/NotSupport.java +7 -0
- data/src/main/java/com/openfeint/memcached/transcoder/MarshalTranscoder.java +91 -0
- data/src/main/java/com/openfeint/memcached/transcoder/MarshalZlibTranscoder.java +103 -0
- data/src/main/java/net/spy/memcached/KetamaNodeLocator.java +165 -0
- data/src/main/java/net/spy/memcached/util/DefaultKetamaNodeLocatorConfiguration.java +104 -0
- data/target/spymemcached-ext-0.0.2.jar +0 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 33af178d60f18f9c5ce59cd59142f0bbbb31585b
|
4
|
+
data.tar.gz: eb261ab365db08a402e40cafa0183888d6969868
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67725858026775347fe6852f68876db289faf4c68ca865a10cadabdbe46f724401ea42408637bfa641ee879d6fba3f9c62de93b228bdb373066fc1eff5b0f2b8
|
7
|
+
data.tar.gz: cb58362f6051ca60e5321e7ad675adfe020bde83dc8f9f48193d5d22e244547595ffc7d7ecdb841c852e50989ab0b3965df87699059585b014cf8ee566a7dffa
|
data/.gitignore
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Gemfile.lock
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
.bundle
|
5
|
+
.config
|
6
|
+
coverage
|
7
|
+
InstalledFiles
|
8
|
+
lib/bundler/man
|
9
|
+
pkg
|
10
|
+
rdoc
|
11
|
+
spec/reports
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tmp
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
target/classes
|
22
|
+
target/surefire
|
23
|
+
target/dependency-reduced-pom.xml
|
24
|
+
target/original-spymemcached-ext-*
|
25
|
+
target/original-xmemcached-ext-*
|
26
|
+
target/maven*
|
27
|
+
|
28
|
+
.idea/
|
29
|
+
out/
|
30
|
+
spymemcached-ext.iml
|
31
|
+
src/main/Main.iml
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
## 0.5.5 (May 15, 2013)
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
|
5
|
+
- forgot to update spymemcached-ext-0.0.1.jar before last release
|
6
|
+
|
7
|
+
## 0.5.4 (May 14, 2013)
|
8
|
+
|
9
|
+
Features:
|
10
|
+
|
11
|
+
- add Memcached#active? method
|
12
|
+
|
13
|
+
## 0.5.3 (Apr 1, 2013)
|
14
|
+
|
15
|
+
Bugfixes:
|
16
|
+
|
17
|
+
- use the absolute path to the JAR file
|
18
|
+
|
19
|
+
## 0.5.2 (Feb 15, 2013)
|
20
|
+
|
21
|
+
Bugfixes:
|
22
|
+
|
23
|
+
- do not throw error when get/read cache failed by Memcached::Rails
|
24
|
+
|
25
|
+
## 0.5.1 (Nov 10, 2012)
|
26
|
+
|
27
|
+
Bugfixes:
|
28
|
+
|
29
|
+
- ignore nil value in Memcached options
|
30
|
+
|
31
|
+
Features:
|
32
|
+
|
33
|
+
- clean up java code
|
34
|
+
- separate slow timeout tests
|
35
|
+
|
36
|
+
## 0.5.0 (Aug 22, 2012)
|
37
|
+
|
38
|
+
Bugfixes:
|
39
|
+
|
40
|
+
- fix Memcached increment/decrement, which works with MarshalTranscoder
|
41
|
+
now
|
42
|
+
|
43
|
+
Features:
|
44
|
+
|
45
|
+
- update spymemcached to 2.8.3, which set shouldOptimize as false by
|
46
|
+
default
|
47
|
+
- add Memcached::ATimeoutOccurred exception
|
48
|
+
- accept exception_retry_limit option
|
49
|
+
|
50
|
+
## 0.4.1 (Aug 17, 2012)
|
51
|
+
|
52
|
+
Bugfixes:
|
53
|
+
|
54
|
+
- fix ClassCastException from Long to RubyFixnum
|
55
|
+
|
56
|
+
## 0.4.0 (Aug 16, 2012)
|
57
|
+
|
58
|
+
Bugfixes:
|
59
|
+
|
60
|
+
- set as daemon thread to avoid suspend ruby process (like rake task)
|
61
|
+
|
62
|
+
Features:
|
63
|
+
|
64
|
+
- support get with multiple keys
|
65
|
+
- add Memcached::Rails as rails cache_store
|
66
|
+
- use jruby annotation to reduce method definitions
|
67
|
+
|
68
|
+
## 0.3.0 (Aug 7, 2012)
|
69
|
+
|
70
|
+
Features:
|
71
|
+
|
72
|
+
- rewrite with pure jruby implementation
|
73
|
+
|
74
|
+
## 0.2.0 (Jul 29, 2012)
|
75
|
+
|
76
|
+
Bugfixes:
|
77
|
+
|
78
|
+
- set method should not be async
|
79
|
+
|
80
|
+
Features:
|
81
|
+
|
82
|
+
- allow to change hash, distribution and binary protocol
|
83
|
+
|
84
|
+
## 0.1.0 (Jul 24, 2012)
|
85
|
+
|
86
|
+
Features:
|
87
|
+
|
88
|
+
- wrap java library spymemcached
|
89
|
+
- compatible hash and distribution algorithms with memcached.gem
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Richard Huang (flyerhzm@gmail.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# jruby-memcached
|
2
|
+
|
3
|
+
A jruby memcached gem which is compatible with evan's [memcached][0] gem
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
gem install jruby-memcached
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Now, in Ruby, require the library and instantiate a Memcached object at
|
12
|
+
a global level:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
require 'memcached'
|
16
|
+
$cache = Memcached.new("localhost:11211")
|
17
|
+
```
|
18
|
+
|
19
|
+
Now you can set things and get things:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
value = 'hello'
|
23
|
+
$cache.set 'test', value
|
24
|
+
$cache.get 'test' #=> "hello"
|
25
|
+
```
|
26
|
+
|
27
|
+
You can set with an expiration timeout:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
value = 'hello'
|
31
|
+
$cache.set 'test', value, 1
|
32
|
+
sleep(2)
|
33
|
+
$cache.get 'test' #=> raises Memcached::NotFound
|
34
|
+
```
|
35
|
+
|
36
|
+
You can get multiple values at once:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
value = 'hello'
|
40
|
+
$cache.set 'test', value
|
41
|
+
$cache.set 'test2', value
|
42
|
+
$cache.get ['test', 'test2', 'missing']
|
43
|
+
#=> {"test" => "hello", "test2" => "hello"}
|
44
|
+
```
|
45
|
+
|
46
|
+
You can set a counter and increment it. Note that you must initialize it
|
47
|
+
with an integer, encoded as an unmarshalled ASCII string:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
$cache.increment 'counter' #=> 1
|
51
|
+
$cache.increment 'counter' #=> 2
|
52
|
+
$cache.get('counter').to_i #=> 2
|
53
|
+
```
|
54
|
+
|
55
|
+
You can get some server stats:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
$cache.stats #=> {..., :bytes_written=>[62], :version=>["1.2.4"] ...}
|
59
|
+
```
|
60
|
+
|
61
|
+
## Rails
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# config/environment.rb
|
65
|
+
config.cache_store = Memcached::Rails.new(:servers => ['127.0.0.1'])
|
66
|
+
```
|
67
|
+
|
68
|
+
## Benchmarks
|
69
|
+
|
70
|
+
memcached.gem is the fastest memcached gem in MRI,
|
71
|
+
jruby-memcached is the fastest memcached gem in JRuby.
|
72
|
+
See [benchmark][1]
|
73
|
+
|
74
|
+
[0]: https://github.com/evan/memcached
|
75
|
+
[1]: https://github.com/aurorafeint/jruby-memcached/blob/master/benchmark.rb
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require "rake"
|
5
|
+
require "rspec"
|
6
|
+
require "rspec/core/rake_task"
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
9
|
+
require "memcached/version"
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
12
|
+
spec.pattern = "spec/**/*_spec.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => :spec
|
16
|
+
task :test => :spec
|
data/benchmark.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
JRUBY = defined?(JRUBY_VERSION)
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
if JRUBY
|
7
|
+
require 'lib/memcached'
|
8
|
+
require 'jruby-spymemcached'
|
9
|
+
else
|
10
|
+
require 'memcached'
|
11
|
+
end
|
12
|
+
require 'dalli'
|
13
|
+
|
14
|
+
memcached = Memcached.new(['localhost:11211'])
|
15
|
+
spymemcached = Spymemcached.new(['localhost:11211']) if JRUBY
|
16
|
+
dalli = Dalli::Client.new(['localhost:11211'])
|
17
|
+
|
18
|
+
3.to_i.times {
|
19
|
+
Benchmark.bm(30) {|bm|
|
20
|
+
if JRUBY
|
21
|
+
bm.report("jruby-memcached set") {
|
22
|
+
100_000.times { memcached.set('foo', 'bar') }
|
23
|
+
}
|
24
|
+
bm.report("jruby-memcached get") {
|
25
|
+
100_000.times { memcached.get('foo') }
|
26
|
+
}
|
27
|
+
bm.report("jruby-spymemcached set") {
|
28
|
+
100_000.times { spymemcached.set('foo', 'bar') }
|
29
|
+
}
|
30
|
+
bm.report("jruby-spymemcached get") {
|
31
|
+
100_000.times { spymemcached.get('foo') }
|
32
|
+
}
|
33
|
+
else
|
34
|
+
bm.report("memcached set") {
|
35
|
+
100_000.times { memcached.set('foo', 'bar') }
|
36
|
+
}
|
37
|
+
bm.report("memcached get") {
|
38
|
+
100_000.times { memcached.get('foo') }
|
39
|
+
}
|
40
|
+
end
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
3.times {
|
45
|
+
Benchmark.bm(30) {|bm|
|
46
|
+
bm.report("dalli set") {
|
47
|
+
100_000.times { dalli.set('foo', 'bar') }
|
48
|
+
}
|
49
|
+
bm.report("dalli get") {
|
50
|
+
100_000.times { dalli.get('foo') }
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
memcached.quit
|
56
|
+
spymemcached.shutdown if JRUBY
|
57
|
+
dalli.close
|
58
|
+
|
59
|
+
# I run benchmark for each client 3 times, but only list the last result for each.
|
60
|
+
#
|
61
|
+
# MBP 2.8G i7 jruby-memcached 0.3.0
|
62
|
+
#
|
63
|
+
# ruby-1.9.3-p194
|
64
|
+
# ruby benchmark.rb
|
65
|
+
# user system total real
|
66
|
+
# memcached set 1.110000 1.020000 2.130000 ( 4.592509)
|
67
|
+
# memcached get 0.970000 1.000000 1.970000 ( 4.172170)
|
68
|
+
# user system total real
|
69
|
+
# dalli set 8.360000 1.650000 10.010000 ( 10.193101)
|
70
|
+
# dalli get 8.040000 1.670000 9.710000 ( 9.828392)
|
71
|
+
#
|
72
|
+
# jruby-1.6.7.2
|
73
|
+
# jruby --server -Ilib -S benchmark.rb
|
74
|
+
# user system total real
|
75
|
+
# jruby-memcached set 5.842000 0.000000 5.842000 ( 5.842000)
|
76
|
+
# jruby-memcached get 5.561000 0.000000 5.561000 ( 5.561000)
|
77
|
+
# user system total real
|
78
|
+
# jruby-spymemcached set 5.919000 0.000000 5.919000 ( 5.919000)
|
79
|
+
# jruby-spymemcached get 5.615000 0.000000 5.615000 ( 5.615000)
|
80
|
+
# user system total real
|
81
|
+
# dalli set 10.132000 0.000000 10.132000 ( 10.132000)
|
82
|
+
# dalli get 10.600000 0.000000 10.600000 ( 10.600000)
|
83
|
+
#
|
84
|
+
##############################################################################
|
85
|
+
#
|
86
|
+
# MBP 2.8G i7 jruby-memcached 0.1.0
|
87
|
+
#
|
88
|
+
# ruby-1.9.3-p194
|
89
|
+
# ruby benchmark.rb
|
90
|
+
# user system total real
|
91
|
+
# memcached set 1.110000 1.020000 2.130000 ( 4.592509)
|
92
|
+
# memcached get 0.970000 1.000000 1.970000 ( 4.172170)
|
93
|
+
# user system total real
|
94
|
+
# dalli set 8.330000 1.560000 9.890000 ( 10.094499)
|
95
|
+
# dalli get 8.530000 1.680000 10.210000 ( 10.331083)
|
96
|
+
#
|
97
|
+
# jruby-1.6.7.2
|
98
|
+
# jruby --server -Ilib -S benchmark.rb
|
99
|
+
# user system total real
|
100
|
+
# jruby-memcached set 6.902000 0.000000 6.902000 ( 6.902000)
|
101
|
+
# jruby-memcached get 6.845000 0.000000 6.845000 ( 6.845000)
|
102
|
+
# user system total real
|
103
|
+
# dalli set 13.251000 0.000000 13.251000 ( 13.251000)
|
104
|
+
# dalli get 13.536000 0.000000 13.536000 ( 13.536000)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "memcached/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "jruby-memcached-thoughtworks"
|
7
|
+
s.version = Memcached::VERSION
|
8
|
+
s.authors = ["Bill DePhillips"]
|
9
|
+
s.email = ["bill.dephillips@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/ThoughtWorksStudios/jruby-memcached"
|
11
|
+
s.summary = %q{jruby compatible memcached client}
|
12
|
+
s.description = %q{jruby memcacached client which is compatible with memcached gem}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_development_dependency 'rspec'
|
20
|
+
s.add_development_dependency 'mocha'
|
21
|
+
end
|
data/lib/memcached.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'memcached/version'
|
3
|
+
require File.expand_path('../../target/spymemcached-ext-0.0.2.jar', __FILE__)
|
4
|
+
require 'com/openfeint/memcached/memcached'
|
5
|
+
|
6
|
+
class Memcached::Rails
|
7
|
+
attr_reader :logger
|
8
|
+
|
9
|
+
def logger=(logger)
|
10
|
+
@logger = logger
|
11
|
+
end
|
12
|
+
end
|
data/pom.xml
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
2
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
3
|
+
<modelVersion>4.0.0</modelVersion>
|
4
|
+
|
5
|
+
<groupId>net.spy</groupId>
|
6
|
+
<artifactId>spymemcached-ext</artifactId>
|
7
|
+
<version>0.0.2</version>
|
8
|
+
<packaging>jar</packaging>
|
9
|
+
|
10
|
+
<name>spymemcached-ext</name>
|
11
|
+
<url>http://maven.apache.org</url>
|
12
|
+
|
13
|
+
<properties>
|
14
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
15
|
+
</properties>
|
16
|
+
|
17
|
+
<dependencies>
|
18
|
+
<dependency>
|
19
|
+
<groupId>junit</groupId>
|
20
|
+
<artifactId>junit</artifactId>
|
21
|
+
<version>4.10</version>
|
22
|
+
<scope>test</scope>
|
23
|
+
</dependency>
|
24
|
+
<dependency>
|
25
|
+
<groupId>org.jruby</groupId>
|
26
|
+
<artifactId>jruby</artifactId>
|
27
|
+
<version>1.6.7.2</version>
|
28
|
+
</dependency>
|
29
|
+
<dependency>
|
30
|
+
<groupId>net.spy</groupId>
|
31
|
+
<artifactId>spymemcached</artifactId>
|
32
|
+
<version>2.11.4</version>
|
33
|
+
</dependency>
|
34
|
+
</dependencies>
|
35
|
+
|
36
|
+
<build>
|
37
|
+
<plugins>
|
38
|
+
<plugin>
|
39
|
+
<groupId>org.apache.maven.plugins</groupId>
|
40
|
+
<artifactId>maven-surefire-plugin</artifactId>
|
41
|
+
<version>2.12.2</version>
|
42
|
+
<configuration>
|
43
|
+
<parallel>methods</parallel>
|
44
|
+
<threadCount>10</threadCount>
|
45
|
+
</configuration>
|
46
|
+
</plugin>
|
47
|
+
<plugin>
|
48
|
+
<groupId>org.apache.maven.plugins</groupId>
|
49
|
+
<artifactId>maven-shade-plugin</artifactId>
|
50
|
+
<version>1.6</version>
|
51
|
+
<executions>
|
52
|
+
<execution>
|
53
|
+
<phase>package</phase>
|
54
|
+
<goals>
|
55
|
+
<goal>shade</goal>
|
56
|
+
</goals>
|
57
|
+
<configuration>
|
58
|
+
<artifactSet>
|
59
|
+
<excludes>
|
60
|
+
<exclude>org.jruby:jruby</exclude>
|
61
|
+
</excludes>
|
62
|
+
</artifactSet>
|
63
|
+
</configuration>
|
64
|
+
</execution>
|
65
|
+
</executions>
|
66
|
+
</plugin>
|
67
|
+
</plugins>
|
68
|
+
</build>
|
69
|
+
</project>
|