Class: Moneta::Adapters::TokyoCabinet
- Inherits:
-
Moneta::Adapter
- Object
- Moneta::Adapter
- Moneta::Adapters::TokyoCabinet
- Includes:
- CreateSupport, EachKeySupport, HashAdapter, IncrementSupport
- Defined in:
- lib/moneta/adapters/tokyocabinet.rb
Overview
TokyoCabinet backend
Instance Attribute Summary
Attributes included from HashAdapter
Attributes inherited from Moneta::Adapter
Instance Method Summary collapse
-
#close ⇒ Object
Explicitly close the store.
-
#create(key, value, options = {}) ⇒ Boolean
Atomically sets a key to value if it’s not set.
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
- #initialize(options = {}) ⇒ Object constructor
Methods included from EachKeySupport
Methods included from CreateSupport
Methods included from IncrementSupport
Methods included from HashAdapter
#clear, #fetch_values, #key?, #load, #merge!, #slice, #store, #values_at
Methods inherited from Moneta::Adapter
backend, backend_block, backend_required?
Methods included from Config
Methods included from Defaults
#[], #[]=, #decrement, #each_key, #features, #fetch, #fetch_values, included, #increment, #key?, #merge!, #slice, #supports?, #update, #values_at
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/moneta/adapters/tokyocabinet.rb', line 18 backend do |file:, type: :hdb| case type when :bdb ::TokyoCabinet::BDB.new.tap do |backend| backend.open(file, ::TokyoCabinet::BDB::OWRITER | ::TokyoCabinet::BDB::OCREAT) or raise backend.errmsg(backend.ecode) end when :hdb ::TokyoCabinet::HDB.new.tap do |backend| backend.open(file, ::TokyoCabinet::HDB::OWRITER | ::TokyoCabinet::HDB::OCREAT) or raise backend.errmsg(backend.ecode) end else raise ArgumentError, ":type must be :bdb or :hdb" end end |
Instance Method Details
#close ⇒ Object
Explicitly close the store
50 51 52 53 |
# File 'lib/moneta/adapters/tokyocabinet.rb', line 50 def close @backend.close nil end |
#create(key, value, options = {}) ⇒ Boolean
Note:
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Atomically sets a key to value if it’s not set.
45 46 47 |
# File 'lib/moneta/adapters/tokyocabinet.rb', line 45 def create(key, value, = {}) @backend.putkeep(key, value) end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
36 37 38 39 40 41 42 |
# File 'lib/moneta/adapters/tokyocabinet.rb', line 36 def delete(key, = {}) value = load(key, ) if value @backend.delete(key) value end end |