moneta 0.7.9 → 0.7.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/CHANGES +6 -0
- data/Gemfile +2 -0
- data/README.md +7 -4
- data/Rakefile +2 -2
- data/lib/moneta.rb +1 -0
- data/lib/moneta/adapters/activerecord.rb +1 -2
- data/lib/moneta/adapters/cassandra.rb +31 -26
- data/lib/moneta/adapters/cookie.rb +2 -2
- data/lib/moneta/adapters/couch.rb +5 -3
- data/lib/moneta/adapters/daybreak.rb +13 -9
- data/lib/moneta/adapters/dbm.rb +7 -3
- data/lib/moneta/adapters/file.rb +4 -3
- data/lib/moneta/adapters/fog.rb +5 -2
- data/lib/moneta/adapters/gdbm.rb +7 -3
- data/lib/moneta/adapters/hbase.rb +11 -9
- data/lib/moneta/adapters/kyotocabinet.rb +13 -8
- data/lib/moneta/adapters/leveldb.rb +9 -5
- data/lib/moneta/adapters/localmemcache.rb +7 -3
- data/lib/moneta/adapters/memcached/dalli.rb +16 -11
- data/lib/moneta/adapters/memcached/native.rb +20 -15
- data/lib/moneta/adapters/memory.rb +2 -1
- data/lib/moneta/adapters/mongo.rb +13 -8
- data/lib/moneta/adapters/pstore.rb +24 -21
- data/lib/moneta/adapters/redis.rb +14 -12
- data/lib/moneta/adapters/restclient.rb +10 -7
- data/lib/moneta/adapters/riak.rb +5 -1
- data/lib/moneta/adapters/sdbm.rb +7 -3
- data/lib/moneta/adapters/sequel.rb +13 -8
- data/lib/moneta/adapters/sqlite.rb +15 -10
- data/lib/moneta/adapters/tdb.rb +8 -4
- data/lib/moneta/adapters/tokyocabinet.rb +15 -10
- data/lib/moneta/adapters/tokyotyrant.rb +107 -0
- data/lib/moneta/cache.rb +17 -17
- data/lib/moneta/mixins.rb +7 -5
- data/lib/moneta/version.rb +1 -1
- data/lib/rack/moneta_store.rb +1 -1
- data/lib/rack/session/moneta.rb +6 -3
- data/script/benchmarks +28 -28
- data/script/generate-specs +96 -41
- data/script/memusage +40 -0
- data/script/start-services +1 -0
- data/spec/helper.rb +4 -1
- data/spec/moneta/adapter_tokyotyrant_spec.rb +30 -0
- data/spec/moneta/cache_file_memory_spec.rb +3 -3
- data/spec/moneta/cache_memory_null_spec.rb +1 -1
- data/spec/moneta/simple_tokyotyrant_spec.rb +155 -0
- data/spec/moneta/simple_tokyotyrant_with_expires_spec.rb +157 -0
- data/spec/monetaspecs.rb +79 -37
- data/spec/rack/moneta_store_spec.rb +1 -1
- data/spec/rack/session_moneta_spec.rb +27 -0
- metadata +10 -3
data/.travis.yml
CHANGED
@@ -8,9 +8,9 @@ rvm:
|
|
8
8
|
- rbx-19mode
|
9
9
|
before_install:
|
10
10
|
- script/kill-travis
|
11
|
-
- script/start-services
|
12
11
|
- script/install-kyotocabinet
|
13
|
-
- sudo apt-get install -qq libtokyocabinet8 libtokyocabinet-dev liblzo2-dev libtdb-dev
|
12
|
+
- sudo apt-get install -qq libtokyocabinet8 libtokyocabinet-dev liblzo2-dev libtdb-dev tokyotyrant
|
13
|
+
- script/start-services
|
14
14
|
- script/install-bundle
|
15
15
|
- script/upload-bundle
|
16
16
|
install: 'echo "Bundle installed"'
|
data/CHANGES
CHANGED
data/Gemfile
CHANGED
@@ -4,6 +4,7 @@ gemspec
|
|
4
4
|
# Testing
|
5
5
|
gem 'rake'
|
6
6
|
gem 'rspec'
|
7
|
+
gem 'rspec-retry'
|
7
8
|
|
8
9
|
# Serializer used by Transformer
|
9
10
|
gem 'tnetstring'
|
@@ -37,6 +38,7 @@ gem 'sequel'
|
|
37
38
|
gem 'dalli'
|
38
39
|
gem 'riak-client'
|
39
40
|
gem 'cassandra'
|
41
|
+
gem 'tokyotyrant'
|
40
42
|
#gem 'hbaserb'
|
41
43
|
#gem 'localmemcache'
|
42
44
|
gem 'tdb', :platforms => :ruby
|
data/README.md
CHANGED
@@ -107,6 +107,7 @@ Out of the box, it supports the following backends. Use the backend name symbol
|
|
107
107
|
* [SDBM](http://www.ruby-doc.org/stdlib/libdoc/sdbm/rdoc/SDBM.html) (`:SDBM`)
|
108
108
|
* [KyotoCabinet](http://fallabs.com/kyotocabinet/) (`:KyotoCabinet`)
|
109
109
|
* [TokyoCabinet](http://fallabs.com/tokyocabinet/) (`:TokyoCabinet`)
|
110
|
+
* [TokyoTyrant](http://fallabs.com/tokyotyrant/) (`:TokyoTyrant`)
|
110
111
|
* [Simple Samba database TDB](http://tdb.samba.org/) (`:TDB`)
|
111
112
|
* Document databases:
|
112
113
|
* [CouchDB](http://couchdb.apache.org/) (`:Couch`)
|
@@ -147,6 +148,8 @@ __NOTE:__ <a name="backend-matrix">The backend matrix</a> is much more readable
|
|
147
148
|
|
148
149
|
<tr><td>PStore</td><td>-</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:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td><a href="http://ruby-doc.org/stdlib/libdoc/pstore/rdoc/PStore.html">PStore</a> store</td></tr>
|
149
150
|
|
151
|
+
<tr><td>TokyoTyrant</td><td>tokoytyrant</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:#5F5">✓</td><td style="text-align:center;background:#F44">✗</td><td style="text-align:center;background:#5F5">✓</td><td><a href="http://fallabs.com/tokyotyrant/">TokyoTyrant</a> database</td></tr>
|
152
|
+
|
150
153
|
<tr><td>YAML</td><td>-</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:#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/yaml/rdoc/YAML/Store.html">YAML</a> store</td></tr>
|
151
154
|
|
152
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>
|
@@ -204,7 +207,7 @@ __NOTE:__ <a name="backend-matrix">The backend matrix</a> is much more readable
|
|
204
207
|
* [1]: Make adapters thread-safe by using `Moneta::Lock` or by passing the option `:threadsafe => true` to `Moneta#new`. There is also `Moneta::Pool` which can be used to share a store between multiple threads if the store is multi-process safe. I recommend to add the option `:threadsafe` to ensure thread-safety since for example under JRuby and Rubinius even the basic datastructures are not thread safe due to the lack of a global interpreter lock (GIL). This differs from MRI where some adapters might appear thread safe already but only due to the GIL.
|
205
208
|
* [2]: Share a Moneta store between multiple processes using `Moneta::Shared` (See below).
|
206
209
|
* [3]: Add expiration support by using `Moneta::Expires` or by passing the option `:expires => true` to `Moneta#new`.
|
207
|
-
* [4]: There are some servers which use the memcached protocol but which are persistent (e.g. [MemcacheDB](http://memcachedb.org/), [Kai](http://sourceforge.net/apps/mediawiki/kai), [IronCache](http://dev.iron.io/cache/reference/memcache/), [Roma](https://github.com/roma/roma/tree))
|
210
|
+
* [4]: There are some servers which use the memcached protocol but which are persistent (e.g. [MemcacheDB](http://memcachedb.org/), [Kai](http://sourceforge.net/apps/mediawiki/kai), [IronCache](http://dev.iron.io/cache/reference/memcache/), [Roma](https://github.com/roma/roma/tree) and [Flare](http://labs.gree.jp/Top/OpenSource/Flare-en.html))
|
208
211
|
* [5]: Depends on server
|
209
212
|
* [6]: Store is multi-process safe because it is an in-memory store, values are not shared between multiple processes
|
210
213
|
* [7]: Store is multi-process safe, but not synchronized automatically between multiple processes
|
@@ -454,7 +457,7 @@ end
|
|
454
457
|
begin
|
455
458
|
mutex.lock
|
456
459
|
mutex.locked? # returns true
|
457
|
-
...
|
460
|
+
# ...
|
458
461
|
ensure
|
459
462
|
mutex.unlock
|
460
463
|
end
|
@@ -467,13 +470,13 @@ semaphore = Moneta::Semaphore.new(store, 'semaphore_counter', max_concurrent)
|
|
467
470
|
|
468
471
|
semaphore.synchronize do
|
469
472
|
semaphore.locked? # returns true
|
470
|
-
...
|
473
|
+
# ...
|
471
474
|
end
|
472
475
|
|
473
476
|
begin
|
474
477
|
semaphore.enter
|
475
478
|
semaphore.locked? # returns true
|
476
|
-
...
|
479
|
+
# ...
|
477
480
|
ensure
|
478
481
|
semaphore.leave
|
479
482
|
end
|
data/Rakefile
CHANGED
@@ -35,13 +35,13 @@ task :test do
|
|
35
35
|
specs.shuffle!
|
36
36
|
srand(old_seed)
|
37
37
|
|
38
|
-
unstable = specs.select {|s| s =~ /quicklz|
|
38
|
+
unstable = specs.select {|s| s =~ /quicklz|action_dispatch/ }
|
39
39
|
specs -= unstable
|
40
40
|
end
|
41
41
|
|
42
42
|
# Memcached and Redis specs cannot be used in parallel
|
43
43
|
# because of flushing and lacking namespaces
|
44
|
-
parallel = specs.reject {|s| s =~ /memcached|redis|client|shared|riak/ }
|
44
|
+
parallel = specs.reject {|s| s =~ /memcached|redis|client|shared|riak|tokyotyrant|couch|cassandra/ }
|
45
45
|
serial = specs - parallel
|
46
46
|
|
47
47
|
if ENV['TEST_GROUP'] =~ /^(\d+)\/(\d+)$/
|
data/lib/moneta.rb
CHANGED
@@ -57,6 +57,7 @@ module Moneta
|
|
57
57
|
autoload :Sqlite, 'moneta/adapters/sqlite'
|
58
58
|
autoload :TDB, 'moneta/adapters/tdb'
|
59
59
|
autoload :TokyoCabinet, 'moneta/adapters/tokyocabinet'
|
60
|
+
autoload :TokyoTyrant, 'moneta/adapters/tokyotyrant'
|
60
61
|
autoload :YAML, 'moneta/adapters/yaml'
|
61
62
|
end
|
62
63
|
|
@@ -8,13 +8,12 @@ module Moneta
|
|
8
8
|
include Defaults
|
9
9
|
|
10
10
|
supports :create, :increment
|
11
|
+
attr_reader :table
|
11
12
|
|
12
13
|
def self.tables
|
13
14
|
@tables ||= {}
|
14
15
|
end
|
15
16
|
|
16
|
-
attr_reader :table
|
17
|
-
|
18
17
|
# @param [Hash] options
|
19
18
|
# @option options [String] :table ('moneta') Table name
|
20
19
|
# @option options [Hash] :connection ActiveRecord connection configuration
|
@@ -11,43 +11,48 @@ module Moneta
|
|
11
11
|
include Defaults
|
12
12
|
include ExpiresSupport
|
13
13
|
|
14
|
+
attr_reader :backend
|
15
|
+
|
14
16
|
# @param [Hash] options
|
15
17
|
# @option options [String] :keyspace ('moneta') Cassandra keyspace
|
16
18
|
# @option options [String] :column_family ('moneta') Cassandra column family
|
17
19
|
# @option options [String] :host ('127.0.0.1') Server host name
|
18
20
|
# @option options [Integer] :port (9160) Server port
|
19
21
|
# @option options [Integer] :expires Default expiration time
|
22
|
+
# @option options [::Cassandra] :backend Use existing backend instance
|
20
23
|
def initialize(options = {})
|
21
|
-
options[:host] ||= '127.0.0.1'
|
22
|
-
options[:port] ||= 9160
|
23
24
|
self.default_expires = options[:expires]
|
24
|
-
keyspace = (options[:keyspace] ||= 'moneta')
|
25
25
|
@cf = (options[:column_family] || 'moneta').to_sym
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
if options[:backend]
|
27
|
+
@backend = options[:backend]
|
28
|
+
else
|
29
|
+
keyspace = options[:keyspace] || 'moneta'
|
30
|
+
@backend = ::Cassandra.new('system', "#{options[:host] || '127.0.0.1'}:#{options[:port] || 9160}")
|
31
|
+
unless @backend.keyspaces.include?(keyspace)
|
32
|
+
cf_def = ::Cassandra::ColumnFamily.new(:keyspace => keyspace, :name => @cf.to_s)
|
33
|
+
ks_def = ::Cassandra::Keyspace.new(:name => keyspace,
|
34
|
+
:strategy_class => 'SimpleStrategy',
|
35
|
+
:strategy_options => { 'replication_factor' => '1' },
|
36
|
+
:replication_factor => 1,
|
37
|
+
:cf_defs => [cf_def])
|
38
|
+
# Wait for keyspace to be created (issue #24)
|
39
|
+
10.times do
|
40
|
+
begin
|
41
|
+
@backend.add_keyspace(ks_def)
|
42
|
+
rescue Exception => ex
|
43
|
+
warn "Moneta::Adapters::Cassandra - #{ex.message}"
|
44
|
+
end
|
45
|
+
break if @backend.keyspaces.include?(keyspace)
|
46
|
+
sleep 0.1
|
40
47
|
end
|
41
|
-
break if @client.keyspaces.include?(keyspace)
|
42
|
-
sleep 0.1
|
43
48
|
end
|
49
|
+
@backend.keyspace = keyspace
|
44
50
|
end
|
45
|
-
@client.keyspace = keyspace
|
46
51
|
end
|
47
52
|
|
48
53
|
# (see Proxy#key?)
|
49
54
|
def key?(key, options = {})
|
50
|
-
if @
|
55
|
+
if @backend.exists?(@cf, key)
|
51
56
|
load(key, options) if options.include?(:expires)
|
52
57
|
true
|
53
58
|
else
|
@@ -57,31 +62,31 @@ module Moneta
|
|
57
62
|
|
58
63
|
# (see Proxy#load)
|
59
64
|
def load(key, options = {})
|
60
|
-
value = @
|
65
|
+
value = @backend.get(@cf, key)
|
61
66
|
if value
|
62
67
|
expires = expires_value(options, nil)
|
63
|
-
@
|
68
|
+
@backend.insert(@cf, key, {'value' => value['value'] }, :ttl => expires || nil) if expires != nil
|
64
69
|
value['value']
|
65
70
|
end
|
66
71
|
end
|
67
72
|
|
68
73
|
# (see Proxy#store)
|
69
74
|
def store(key, value, options = {})
|
70
|
-
@
|
75
|
+
@backend.insert(@cf, key, {'value' => value}, :ttl => expires_value(options) || nil)
|
71
76
|
value
|
72
77
|
end
|
73
78
|
|
74
79
|
# (see Proxy#delete)
|
75
80
|
def delete(key, options = {})
|
76
81
|
if value = load(key, options)
|
77
|
-
@
|
82
|
+
@backend.remove(@cf, key)
|
78
83
|
value
|
79
84
|
end
|
80
85
|
end
|
81
86
|
|
82
87
|
# (see Proxy#clear)
|
83
88
|
def clear(options = {})
|
84
|
-
@
|
89
|
+
@backend.each_key(@cf) do |key|
|
85
90
|
delete(key)
|
86
91
|
end
|
87
92
|
self
|
@@ -27,7 +27,7 @@ module Moneta
|
|
27
27
|
|
28
28
|
# (see Proxy#clear)
|
29
29
|
def clear(options = {})
|
30
|
-
@
|
30
|
+
@backend.each_key { |key| @cookies[key] = nil }
|
31
31
|
super
|
32
32
|
self
|
33
33
|
end
|
@@ -35,7 +35,7 @@ module Moneta
|
|
35
35
|
# Reset the cookie store
|
36
36
|
# This method is used by the middleware.
|
37
37
|
def reset(cookies)
|
38
|
-
@cookies, @
|
38
|
+
@cookies, @backend = {}, cookies
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -7,13 +7,15 @@ module Moneta
|
|
7
7
|
class Couch
|
8
8
|
include Defaults
|
9
9
|
|
10
|
+
attr_reader :backend
|
11
|
+
|
10
12
|
# @param [Hash] options
|
11
13
|
# @option options [String] :host ('http://127.0.0.1:5984') Couch host
|
12
14
|
# @option options [String] :db ('moneta') Couch database
|
15
|
+
# @option options [::CouchRest] :backend Use existing backend instance
|
13
16
|
def initialize(options = {})
|
14
|
-
options[:
|
15
|
-
options[:
|
16
|
-
@db = CouchRest.new(options[:host]).database!(options[:db])
|
17
|
+
@backend = options[:backend] || CouchRest.new(options[:host] || '127.0.0.1:5984')
|
18
|
+
@db = @backend.database!(options[:db] || 'moneta')
|
17
19
|
end
|
18
20
|
|
19
21
|
# (see Proxy#key?)
|
@@ -7,37 +7,41 @@ module Moneta
|
|
7
7
|
class Daybreak < Memory
|
8
8
|
# @param [Hash] options
|
9
9
|
# @option options [String] :file Database file
|
10
|
+
# @option options [::Daybreak] :backend Use existing backend instance
|
10
11
|
def initialize(options = {})
|
11
|
-
|
12
|
-
|
12
|
+
@backend = options[:backend] ||
|
13
|
+
begin
|
14
|
+
raise ArgumentError, 'Option :file is required' unless options[:file]
|
15
|
+
::Daybreak::DB.new(options[:file], :serializer => ::Daybreak::Serializer::None)
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
# (see Proxy#load)
|
16
20
|
def load(key, options = {})
|
17
|
-
@
|
18
|
-
@
|
21
|
+
@backend.load if options[:sync]
|
22
|
+
@backend[key]
|
19
23
|
end
|
20
24
|
|
21
25
|
# (see Proxy#store)
|
22
26
|
def store(key, value, options = {})
|
23
|
-
@
|
24
|
-
@
|
27
|
+
@backend[key] = value
|
28
|
+
@backend.flush if options[:sync]
|
25
29
|
value
|
26
30
|
end
|
27
31
|
|
28
32
|
# (see Proxy#increment)
|
29
33
|
def increment(key, amount = 1, options = {})
|
30
|
-
@
|
34
|
+
@backend.lock { super }
|
31
35
|
end
|
32
36
|
|
33
37
|
# (see Proxy#create)
|
34
38
|
def create(key, value, options = {})
|
35
|
-
@
|
39
|
+
@backend.lock { super }
|
36
40
|
end
|
37
41
|
|
38
42
|
# (see Proxy#close)
|
39
43
|
def close
|
40
|
-
@
|
44
|
+
@backend.close
|
41
45
|
end
|
42
46
|
end
|
43
47
|
end
|
data/lib/moneta/adapters/dbm.rb
CHANGED
@@ -7,14 +7,18 @@ module Moneta
|
|
7
7
|
class DBM < Memory
|
8
8
|
# @param [Hash] options
|
9
9
|
# @option options [String] :file Database file
|
10
|
+
# @option options [::DBM] :backend Use existing backend instance
|
10
11
|
def initialize(options = {})
|
11
|
-
|
12
|
-
|
12
|
+
@backend = options[:backend] ||
|
13
|
+
begin
|
14
|
+
raise ArgumentError, 'Option :file is required' unless options[:file]
|
15
|
+
::DBM.new(options[:file])
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
# (see Proxy#close)
|
16
20
|
def close
|
17
|
-
@
|
21
|
+
@backend.close
|
18
22
|
nil
|
19
23
|
end
|
20
24
|
end
|
data/lib/moneta/adapters/file.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'fcntl'
|
3
2
|
|
4
3
|
module Moneta
|
5
4
|
module Adapters
|
@@ -72,8 +71,10 @@ module Moneta
|
|
72
71
|
def create(key, value, options = {})
|
73
72
|
path = store_path(key)
|
74
73
|
FileUtils.mkpath(::File.dirname(path))
|
75
|
-
|
76
|
-
|
74
|
+
::File.open(path, ::File::WRONLY | ::File::CREAT | ::File::EXCL) do |file|
|
75
|
+
file.binmode
|
76
|
+
file.write(value)
|
77
|
+
end
|
77
78
|
true
|
78
79
|
rescue Errno::EEXIST
|
79
80
|
false
|
data/lib/moneta/adapters/fog.rb
CHANGED
@@ -7,13 +7,16 @@ module Moneta
|
|
7
7
|
class Fog
|
8
8
|
include Defaults
|
9
9
|
|
10
|
+
attr_reader :backend
|
11
|
+
|
10
12
|
# @param [Hash] options
|
11
13
|
# @option options [String] :dir Fog directory
|
14
|
+
# @option options [::Fog::Storage] :backend Use existing backend instance
|
12
15
|
# @option options Other options passed to `Fog::Storage#new`
|
13
16
|
def initialize(options = {})
|
14
17
|
raise ArgumentError, 'Option :dir is required' unless dir = options.delete(:dir)
|
15
|
-
|
16
|
-
@directory =
|
18
|
+
@backend = options[:backend] || ::Fog::Storage.new(options)
|
19
|
+
@directory = @backend.directories.get(dir) || @backend.directories.create(:key => dir)
|
17
20
|
end
|
18
21
|
|
19
22
|
# (see Proxy#key?)
|
data/lib/moneta/adapters/gdbm.rb
CHANGED
@@ -7,14 +7,18 @@ module Moneta
|
|
7
7
|
class GDBM < Memory
|
8
8
|
# @param [Hash] options
|
9
9
|
# @option options [String] :file Database file
|
10
|
+
# @option options [::GDBM] :backend Use existing backend instance
|
10
11
|
def initialize(options = {})
|
11
|
-
|
12
|
-
|
12
|
+
@backend = options[:backend] ||
|
13
|
+
begin
|
14
|
+
raise ArgumentError, 'Option :file is required' unless options[:file]
|
15
|
+
::GDBM.new(options[:file])
|
16
|
+
end
|
13
17
|
end
|
14
18
|
|
15
19
|
# (see Proxy#close)
|
16
20
|
def close
|
17
|
-
@
|
21
|
+
@backend.close
|
18
22
|
nil
|
19
23
|
end
|
20
24
|
end
|
@@ -7,22 +7,24 @@ module Moneta
|
|
7
7
|
class HBase
|
8
8
|
include Defaults
|
9
9
|
|
10
|
+
attr_reader :backend
|
11
|
+
|
10
12
|
# @param [Hash] options
|
11
13
|
# @option options [String] :host ('127.0.0.1') Server host name
|
12
14
|
# @option options [Integer] :port (9090) Server port
|
13
15
|
# @option options [String] :table ('moneta') Table name
|
14
16
|
# @option options [String] :column_family ('moneta') Column family
|
15
17
|
# @option options [String] :column ('value') Column
|
18
|
+
# @option options [::HBaseRb::Client] :backend Use existing backend instance
|
16
19
|
def initialize(options = {})
|
17
|
-
options[:host] ||= '127.0.0.1'
|
18
|
-
options[:port] ||= '9090'
|
19
|
-
options[:table] ||= 'moneta'
|
20
20
|
options[:column] ||= 'value'
|
21
|
+
options[:table] ||= 'moneta'
|
21
22
|
cf = (options[:column_family] || 'moneta')
|
22
|
-
@db = HBaseRb::Client.new(options[:host], options[:port])
|
23
|
-
@db.create_table(options[:table], cf) unless @db.has_table?(options[:table])
|
24
|
-
@table = @db.get_table(options[:table])
|
25
23
|
@column = "#{cf}:#{options[:column]}"
|
24
|
+
@backend = options[:backend] ||
|
25
|
+
HBaseRb::Client.new(options[:host] || '127.0.0.1', options[:port] || '9090')
|
26
|
+
@backend.create_table(options[:table], cf) unless @backend.has_table?(options[:table])
|
27
|
+
@table = @backend.get_table(options[:table])
|
26
28
|
end
|
27
29
|
|
28
30
|
# (see Proxy#key?)
|
@@ -54,7 +56,7 @@ module Moneta
|
|
54
56
|
def delete(key, options = {})
|
55
57
|
if value = load(key, options)
|
56
58
|
@table.delete_row(key)
|
57
|
-
|
59
|
+
value
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
@@ -68,7 +70,7 @@ module Moneta
|
|
68
70
|
|
69
71
|
# (see Proxy#close)
|
70
72
|
def close
|
71
|
-
@
|
73
|
+
@backend.close
|
72
74
|
nil
|
73
75
|
end
|
74
76
|
|
@@ -81,7 +83,7 @@ module Moneta
|
|
81
83
|
[intvalue].pack('Q>')
|
82
84
|
elsif value.bytesize >= 8
|
83
85
|
# Add nul character to make value distinguishable from integer
|
84
|
-
value
|
86
|
+
value + "\0"
|
85
87
|
else
|
86
88
|
value
|
87
89
|
end
|