Class: Moneta::Adapters::KyotoCabinet
- Defined in:
- lib/moneta/adapters/kyotocabinet.rb
Overview
KyotoCabinet 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 = {}) ⇒ KyotoCabinet
constructor
A new instance of KyotoCabinet.
-
#key?(key, options = {}) ⇒ Boolean
Exists the value with key.
Methods included from CreateSupport
Methods included from IncrementSupport
Methods included from HashAdapter
Methods included from Defaults
#[], #[]=, #decrement, #features, #fetch, included, #increment, #supports?
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ KyotoCabinet
Returns a new instance of KyotoCabinet.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/moneta/adapters/kyotocabinet.rb', line 11 def initialize( = {}) if [:backend] @backend = [:backend] else raise ArgumentError, 'Option :file is required' unless [:file] @backend = ::KyotoCabinet::DB.new raise @backend.error.to_s unless @backend.open([:file], ::KyotoCabinet::DB::OWRITER | ::KyotoCabinet::DB::OCREATE) end end |
Instance Method Details
#close ⇒ Object
Explicitly close the store
38 39 40 41 |
# File 'lib/moneta/adapters/kyotocabinet.rb', line 38 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.
33 34 35 |
# File 'lib/moneta/adapters/kyotocabinet.rb', line 33 def create(key, value, = {}) @backend.add(key, value) end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
28 29 30 |
# File 'lib/moneta/adapters/kyotocabinet.rb', line 28 def delete(key, = {}) @backend.seize(key) end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
23 24 25 |
# File 'lib/moneta/adapters/kyotocabinet.rb', line 23 def key?(key, = {}) @backend.check(key) >= 0 end |