moneta 0.7.14 → 0.7.15
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/.travis.yml +1 -0
- data/.yardopts +1 -1
- data/CHANGES +5 -0
- data/CONTRIBUTORS +21 -0
- data/Gemfile +8 -4
- data/README.md +30 -3
- data/Rakefile +1 -3
- data/lib/moneta/adapters/cassandra.rb +7 -3
- data/lib/moneta/adapters/file.rb +10 -10
- data/lib/moneta/adapters/riak.rb +1 -3
- data/lib/moneta/mixins.rb +1 -3
- data/lib/moneta/version.rb +1 -1
- data/script/generate-specs +10 -6
- data/spec/monetaspecs.rb +10 -6
- metadata +3 -2
data/.travis.yml
CHANGED
data/.yardopts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
- README.md SPEC.md CHANGES LICENSE
|
1
|
+
- README.md SPEC.md CHANGES LICENSE CONTRIBUTORS
|
data/CHANGES
CHANGED
data/CONTRIBUTORS
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Adrian Madrid <aemadrid@gmail.com>
|
2
|
+
Alejandro Crosa <acrosa@sharing.local>
|
3
|
+
Anthony Eden <anthonyeden@gmail.com>
|
4
|
+
Benjamin Yu <benjaminlyu@gmail.com>
|
5
|
+
Ben Schwarz <ben.schwarz@gmail.com>
|
6
|
+
Daniel Mendler <mail@daniel-mendler.de>
|
7
|
+
Derek Kastner <dkastner@gmail.com>
|
8
|
+
Dylan Egan <me@dylanegan.com>
|
9
|
+
Hampton Catlin <hcatlin@gmail.com>
|
10
|
+
Hannes Georg <hannes.georg@xing.com>
|
11
|
+
Scott Wadden <scott.wadden@gmail.com>
|
12
|
+
Jari Bakken <jari.bakken@gmail.com>
|
13
|
+
Jeremy Voorhis <jvoorhis@gmail.com>
|
14
|
+
Jon Crosby <jon@joncrosby.me>
|
15
|
+
lakshan <lakshan@web2media.net>
|
16
|
+
Potapov Sergey <blake131313@gmail.com>
|
17
|
+
Quin Hoxie <quin@aboutus.org>
|
18
|
+
Tom Meier <ozmeier@yahoo.co.uk>
|
19
|
+
Xavier Shay <xavier@rhnh.net>
|
20
|
+
Yehuda Katz <wycats@gmail.com>
|
21
|
+
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
gemspec
|
3
3
|
|
4
4
|
# Testing
|
@@ -18,7 +18,9 @@ gem 'msgpack-jruby', :platforms => :jruby
|
|
18
18
|
gem 'bert', :platforms => :ruby
|
19
19
|
|
20
20
|
# Compressors used by Transformer
|
21
|
-
|
21
|
+
if RUBY_VERSION < '2.0'
|
22
|
+
gem 'bzip2-ruby', :platforms => :mri # Only on mri currently
|
23
|
+
end
|
22
24
|
gem 'ruby-lzma', :platforms => :ruby
|
23
25
|
gem 'lzoruby', :platforms => :ruby
|
24
26
|
gem 'snappy', :platforms => :ruby
|
@@ -45,8 +47,10 @@ gem 'tokyotyrant'
|
|
45
47
|
#gem 'localmemcache'
|
46
48
|
gem 'tdb', :platforms => :ruby
|
47
49
|
gem 'leveldb-ruby', :platforms => :ruby
|
48
|
-
|
49
|
-
|
50
|
+
if RUBY_VERSION < '2.0'
|
51
|
+
gem 'tokyocabinet', :platforms => :ruby
|
52
|
+
end
|
53
|
+
if RUBY_VERSION < '2.0' && !defined?(JRUBY_VERSION)
|
50
54
|
# FIXME: We have to check manually for jruby
|
51
55
|
# otherwise bundle install --deployment doesn't work
|
52
56
|
gem 'kyotocabinet-ruby', :github => 'minad/kyotocabinet-ruby'
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Moneta: A unified interface for key/value stores
|
2
2
|
|
3
|
-
[](http://rubygems.org/gems/moneta) [](http://travis-ci.org/minad/moneta) [](https://gemnasium.com/minad/moneta) [](http://rubygems.org/gems/moneta) [](http://travis-ci.org/minad/moneta) [](https://gemnasium.com/minad/moneta) [](https://codeclimate.com/github/minad/moneta)
|
4
4
|
|
5
5
|
Moneta provides a standard interface for interacting with various kinds of key/value stores. A short overview of the features:
|
6
6
|
|
@@ -96,7 +96,7 @@ Out of the box, it supports the following backends. Use the backend name symbol
|
|
96
96
|
* Filesystem directory store (`:File`)
|
97
97
|
* Filesystem directory store which spreads files in subdirectories using md5 hash (`:HashFile`)
|
98
98
|
* Key/value databases:
|
99
|
-
* [Berkeley DB](http://www.ruby-doc.org/stdlib/libdoc/dbm/rdoc/DBM.html) (`:DBM`)
|
99
|
+
* [Berkeley DB using DBM interface or NDBM (Depends on Ruby environment)](http://www.ruby-doc.org/stdlib/libdoc/dbm/rdoc/DBM.html) (`:DBM`)
|
100
100
|
* [Cassandra](http://cassandra.apache.org/) (`:Cassandra`)
|
101
101
|
* [Daybreak](http://propublica.github.com/daybreak/) (`:Daybreak`)
|
102
102
|
* [GDBM](http://www.ruby-doc.org/stdlib/libdoc/gdbm/rdoc/GDBM.html) (`:GDBM`)
|
@@ -154,7 +154,7 @@ __NOTE:__ <a name="backend-matrix">The backend matrix</a> is much more readable
|
|
154
154
|
|
155
155
|
<tr><td>Daybreak</td><td>daybreak</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#55F">(✓)<sup>[7]</sup></td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td>Incredibly fast pure-ruby key/value store <a href="http://propublica.github.com/daybreak/">Daybreak</a></td></tr>
|
156
156
|
|
157
|
-
<tr><td>DBM</td><td>-</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td><a href="http://www.ruby-doc.org/stdlib/libdoc/dbm/rdoc/DBM.html">Berkeley DB</a></td></tr>
|
157
|
+
<tr><td>DBM</td><td>-</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td><a href="http://www.ruby-doc.org/stdlib/libdoc/dbm/rdoc/DBM.html">Berkeley DB using DBM interface or NDBM (Depends on Ruby environment)</a></td></tr>
|
158
158
|
|
159
159
|
<tr><td>GDBM</td><td>-</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td><a href="http://www.ruby-doc.org/stdlib/libdoc/gdbm/rdoc/GDBM.html">GDBM</a> database</td></tr>
|
160
160
|
|
@@ -758,6 +758,33 @@ to compare the speed of the different key value stores for different key/value s
|
|
758
758
|
Feel free to add your own configurations! The impact of Moneta should be minimal since it is only a thin layer
|
759
759
|
on top of the different stores.
|
760
760
|
|
761
|
+
|
762
|
+
------
|
763
|
+
|
764
|
+
## How to contribute?
|
765
|
+
|
766
|
+
Always feel free to open an issue on
|
767
|
+
https://github.com/minad/moneta/issues if something doesn't work
|
768
|
+
as you expect it to work. Feedback is also very welcome!
|
769
|
+
|
770
|
+
My only request about patches is that you please try
|
771
|
+
to test them before submitting.
|
772
|
+
|
773
|
+
### Contribute an adapter
|
774
|
+
|
775
|
+
If you want support for another adapter you can at first at it to the list of
|
776
|
+
missing adapters at https://github.com/minad/moneta/issues/16
|
777
|
+
|
778
|
+
If you choose to implement an adapter please also add tests. Usually you
|
779
|
+
only have to add a few lines to `script/generate-specs` to generate appropriate
|
780
|
+
tests for your adapter. Please check also if travis.yml needs changes, for example
|
781
|
+
if you need to start additional services.
|
782
|
+
|
783
|
+
Check if the default settings in Moneta#new are appropriate for your adapter. If
|
784
|
+
not specify a better one.
|
785
|
+
|
786
|
+
Don't forget to edit the README.md and the CHANGES.
|
787
|
+
|
761
788
|
------
|
762
789
|
|
763
790
|
## Alternatives
|
data/Rakefile
CHANGED
@@ -33,11 +33,9 @@ task :test do
|
|
33
33
|
# QuickLZ is also not maintained on Github, but on Bitbucket
|
34
34
|
# and I don't know where the issue tracker is.
|
35
35
|
#
|
36
|
-
# * Cassandra and Riak fail spuriously (An expert has to check the adapters!)
|
37
|
-
#
|
38
36
|
# * PStore and File increment/locking doesn't work correctly on JRuby
|
39
37
|
#
|
40
|
-
unstable = %w(quicklz
|
38
|
+
unstable = %w(quicklz)
|
41
39
|
unstable += %w(file pstore) if defined?(JRUBY_VERSION)
|
42
40
|
|
43
41
|
unstable_re = /#{unstable.join('|')}/
|
@@ -1,12 +1,10 @@
|
|
1
|
-
# Copyright: 2011 TMX Credit
|
2
|
-
# Author: Potapov Sergey (aka Blake)
|
3
|
-
|
4
1
|
require 'cassandra'
|
5
2
|
|
6
3
|
module Moneta
|
7
4
|
module Adapters
|
8
5
|
# Cassandra backend
|
9
6
|
# @api public
|
7
|
+
# @author Potapov Sergey (aka Blake)
|
10
8
|
class Cassandra
|
11
9
|
include Defaults
|
12
10
|
include ExpiresSupport
|
@@ -94,6 +92,12 @@ module Moneta
|
|
94
92
|
end
|
95
93
|
self
|
96
94
|
end
|
95
|
+
|
96
|
+
# (see Proxy#close)
|
97
|
+
def close
|
98
|
+
@backend.disconnect!
|
99
|
+
nil
|
100
|
+
end
|
97
101
|
end
|
98
102
|
end
|
99
103
|
end
|
data/lib/moneta/adapters/file.rb
CHANGED
@@ -29,12 +29,15 @@ module Moneta
|
|
29
29
|
|
30
30
|
# (see Proxy#store)
|
31
31
|
def store(key, value, options = {})
|
32
|
-
path = store_path(key)
|
33
32
|
temp_file = ::File.join(@dir, "value-#{$$}-#{Thread.current.object_id}")
|
33
|
+
path = store_path(key)
|
34
34
|
FileUtils.mkpath(::File.dirname(path))
|
35
35
|
::File.open(temp_file, 'wb') {|f| f.write(value) }
|
36
36
|
::File.rename(temp_file, path)
|
37
37
|
value
|
38
|
+
rescue Exception
|
39
|
+
File.unlink(temp_file) rescue nil
|
40
|
+
raise
|
38
41
|
end
|
39
42
|
|
40
43
|
# (see Proxy#delete)
|
@@ -50,25 +53,22 @@ module Moneta
|
|
50
53
|
temp_dir = "#{@dir}-#{$$}-#{Thread.current.object_id}"
|
51
54
|
::File.rename(@dir, temp_dir)
|
52
55
|
FileUtils.mkpath(@dir)
|
53
|
-
FileUtils.rm_rf(temp_dir)
|
54
56
|
self
|
55
57
|
rescue Errno::ENOENT
|
56
58
|
self
|
59
|
+
ensure
|
60
|
+
FileUtils.rm_rf(temp_dir)
|
57
61
|
end
|
58
62
|
|
59
63
|
# (see Proxy#increment)
|
60
64
|
def increment(key, amount = 1, options = {})
|
61
65
|
path = store_path(key)
|
62
66
|
FileUtils.mkpath(::File.dirname(path))
|
63
|
-
|
64
|
-
::File.open(path, 'ab+') do |f|
|
67
|
+
::File.open(path, ::File::RDWR | ::File::CREAT) do |f|
|
65
68
|
Thread.pass until f.flock(::File::LOCK_EX)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
amount += Utils.to_int(content) if existed || !content.empty?
|
70
|
-
f.truncate(0)
|
71
|
-
f.write(amount.to_s)
|
69
|
+
content = ::File.read(path)
|
70
|
+
amount += Utils.to_int(content) unless content.empty?
|
71
|
+
::File.open(path, 'wb') {|o| o.write(amount.to_s) }
|
72
72
|
amount
|
73
73
|
end
|
74
74
|
end
|
data/lib/moneta/adapters/riak.rb
CHANGED
data/lib/moneta/mixins.rb
CHANGED
@@ -222,7 +222,6 @@ module Moneta
|
|
222
222
|
# @api private
|
223
223
|
module IncrementSupport
|
224
224
|
# (see Defaults#increment)
|
225
|
-
# @api public
|
226
225
|
def increment(key, amount = 1, options = {})
|
227
226
|
value = Utils.to_int(load(key, options)) + amount
|
228
227
|
store(key, value.to_s, options)
|
@@ -239,8 +238,7 @@ module Moneta
|
|
239
238
|
# This is sufficient for non-shared stores or if atomicity is not required.
|
240
239
|
# @api private
|
241
240
|
module CreateSupport
|
242
|
-
# (see
|
243
|
-
# @api public
|
241
|
+
# (see Defaults#create)
|
244
242
|
def create(key, value, options = {})
|
245
243
|
if key? key
|
246
244
|
false
|
data/lib/moneta/version.rb
CHANGED
data/script/generate-specs
CHANGED
@@ -2012,10 +2012,12 @@ end}
|
|
2012
2012
|
SPECS['concurrent_increment'] = %{def increment_thread(name)
|
2013
2013
|
Thread.new do
|
2014
2014
|
s = new_store
|
2015
|
-
|
2016
|
-
|
2015
|
+
100.times do |i|
|
2016
|
+
100.times do |j|
|
2017
|
+
s.increment("counter\#{j}", 1, :expires => false)
|
2018
|
+
Thread.pass if rand(1000) >= 995
|
2019
|
+
end
|
2017
2020
|
s.store("\#{name}\#{i}", i.to_s, :expires => false)
|
2018
|
-
sleep 0.01 if i % 100 == 0
|
2019
2021
|
end
|
2020
2022
|
s.close
|
2021
2023
|
end
|
@@ -2028,12 +2030,14 @@ it 'have atomic increment across multiple processes' do
|
|
2028
2030
|
a.join
|
2029
2031
|
b.join
|
2030
2032
|
c.join
|
2031
|
-
|
2033
|
+
100.times do |i|
|
2032
2034
|
store["a\#{i}"].should == i.to_s
|
2033
2035
|
store["b\#{i}"].should == i.to_s
|
2034
2036
|
store["c\#{i}"].should == i.to_s
|
2035
2037
|
end
|
2036
|
-
|
2038
|
+
100.times do |j|
|
2039
|
+
store.raw["counter\#{j}"].should == 300.to_s
|
2040
|
+
end
|
2037
2041
|
end}
|
2038
2042
|
|
2039
2043
|
SPECS['concurrent_create'] = %{def create_thread(name)
|
@@ -2041,7 +2045,7 @@ SPECS['concurrent_create'] = %{def create_thread(name)
|
|
2041
2045
|
s = new_store
|
2042
2046
|
1000.times do |i|
|
2043
2047
|
s[i.to_s].should == name if s.create(i.to_s, name, :expires => false)
|
2044
|
-
|
2048
|
+
Thread.pass if rand(100) >= 99
|
2045
2049
|
end
|
2046
2050
|
s.close
|
2047
2051
|
end
|
data/spec/monetaspecs.rb
CHANGED
@@ -17164,10 +17164,12 @@ shared_examples_for 'concurrent_increment' do
|
|
17164
17164
|
def increment_thread(name)
|
17165
17165
|
Thread.new do
|
17166
17166
|
s = new_store
|
17167
|
-
|
17168
|
-
|
17167
|
+
100.times do |i|
|
17168
|
+
100.times do |j|
|
17169
|
+
s.increment("counter#{j}", 1, :expires => false)
|
17170
|
+
Thread.pass if rand(1000) >= 995
|
17171
|
+
end
|
17169
17172
|
s.store("#{name}#{i}", i.to_s, :expires => false)
|
17170
|
-
sleep 0.01 if i % 100 == 0
|
17171
17173
|
end
|
17172
17174
|
s.close
|
17173
17175
|
end
|
@@ -17180,12 +17182,14 @@ shared_examples_for 'concurrent_increment' do
|
|
17180
17182
|
a.join
|
17181
17183
|
b.join
|
17182
17184
|
c.join
|
17183
|
-
|
17185
|
+
100.times do |i|
|
17184
17186
|
store["a#{i}"].should == i.to_s
|
17185
17187
|
store["b#{i}"].should == i.to_s
|
17186
17188
|
store["c#{i}"].should == i.to_s
|
17187
17189
|
end
|
17188
|
-
|
17190
|
+
100.times do |j|
|
17191
|
+
store.raw["counter#{j}"].should == 300.to_s
|
17192
|
+
end
|
17189
17193
|
end
|
17190
17194
|
end
|
17191
17195
|
|
@@ -17197,7 +17201,7 @@ shared_examples_for 'concurrent_create' do
|
|
17197
17201
|
s = new_store
|
17198
17202
|
1000.times do |i|
|
17199
17203
|
s[i.to_s].should == name if s.create(i.to_s, name, :expires => false)
|
17200
|
-
|
17204
|
+
Thread.pass if rand(100) >= 99
|
17201
17205
|
end
|
17202
17206
|
s.close
|
17203
17207
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moneta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-
|
14
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: A unified interface to key/value stores
|
17
17
|
email:
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- .travis.yml
|
30
30
|
- .yardopts
|
31
31
|
- CHANGES
|
32
|
+
- CONTRIBUTORS
|
32
33
|
- Gemfile
|
33
34
|
- LICENSE
|
34
35
|
- README.md
|