Class: Moneta::Adapters::TokyoCabinet
- Defined in:
- lib/moneta/adapters/tokyocabinet.rb
Overview
TokyoCabinet backend
Instance Attribute Summary
Attributes included from HashAdapter
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 = {}) ⇒ TokyoCabinet
constructor
A new instance of TokyoCabinet.
Methods included from CreateSupport
Methods included from IncrementSupport
Methods included from HashAdapter
Methods included from Defaults
#[], #[]=, #decrement, #features, #fetch, included, #increment, #key?, #supports?
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ TokyoCabinet
Returns a new instance of TokyoCabinet.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/moneta/adapters/tokyocabinet.rb', line 12 def initialize( = {}) if [:backend] @backend = [:backend] else raise ArgumentError, 'Option :file is required' unless [:file] if [:type] == :bdb @backend = ::TokyoCabinet::BDB.new @backend.open([:file], ::TokyoCabinet::BDB::OWRITER | ::TokyoCabinet::BDB::OCREAT) else @backend = ::TokyoCabinet::HDB.new @backend.open([:file], ::TokyoCabinet::HDB::OWRITER | ::TokyoCabinet::HDB::OCREAT) end or raise @backend.errmsg(@backend.ecode) end end |
Instance Method Details
#close ⇒ Object
Explicitly close the store
42 43 44 45 |
# File 'lib/moneta/adapters/tokyocabinet.rb', line 42 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.
37 38 39 |
# File 'lib/moneta/adapters/tokyocabinet.rb', line 37 def create(key, value, = {}) @backend.putkeep(key, value) end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
28 29 30 31 32 33 34 |
# File 'lib/moneta/adapters/tokyocabinet.rb', line 28 def delete(key, = {}) value = load(key, ) if value @backend.delete(key) value end end |