Class: Moneta::Adapters::LevelDB
- Inherits:
-
Object
- Object
- Moneta::Adapters::LevelDB
- Includes:
- CreateSupport, Defaults, EachKeySupport, HashAdapter, IncrementSupport
- Defined in:
- lib/moneta/adapters/leveldb.rb
Overview
LevelDB backend
Instance Attribute Summary
Attributes included from HashAdapter
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#close ⇒ Object
Explicitly close the store.
-
#each_key ⇒ Object
Calls block once for each key in store, passing the key as a parameter.
-
#initialize(options = {}) ⇒ LevelDB
constructor
A new instance of LevelDB.
-
#key?(key, options = {}) ⇒ Boolean
Exists the value with key.
-
#merge!(*keys, **options) ⇒ Object
Stores the pairs in the key-value store, and returns itself.
-
#values_at(*keys, **options) ⇒ Array<Object, nil>
Returns an array containing the values associated with the given keys, in the same order as the supplied keys.
Methods included from EachKeySupport
Methods included from CreateSupport
Methods included from IncrementSupport
Methods included from HashAdapter
#delete, #fetch_values, #load, #slice, #store
Methods included from Defaults
#[], #[]=, #create, #decrement, #features, #fetch, #fetch_values, included, #increment, #slice, #supports?, #update
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ LevelDB
Returns a new instance of LevelDB.
18 19 20 21 22 23 24 |
# File 'lib/moneta/adapters/leveldb.rb', line 18 def initialize( = {}) @backend = [:backend] || begin raise ArgumentError, 'Option :dir is required' unless [:dir] ::LevelDB::DB.new([:dir]) end end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
32 33 34 35 |
# File 'lib/moneta/adapters/leveldb.rb', line 32 def clear( = {}) @backend.each { |k,| delete(k, ) } self end |
#close ⇒ Object
Explicitly close the store
38 39 40 41 |
# File 'lib/moneta/adapters/leveldb.rb', line 38 def close @backend.close nil end |
#each_key ⇒ Enumerator #each_key {|key| ... } ⇒ self
Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.
Calls block once for each key in store, passing the key as a parameter. If no block is given, an enumerator is returned instead.
44 45 46 47 48 |
# File 'lib/moneta/adapters/leveldb.rb', line 44 def each_key return enum_for(:each_key) { @backend.size } unless block_given? @backend.each { |key, _| yield key } self end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
27 28 29 |
# File 'lib/moneta/adapters/leveldb.rb', line 27 def key?(key, = {}) @backend.includes?(key) end |
#merge!(pairs, options = {}) ⇒ self #merge!(pairs, options = {}) {|key, old_value, new_value| ... } ⇒ self
Some adapters may implement this method atomically, or in two passes when a block is provided. The default implmentation uses #key?, HashAdapter#load and HashAdapter#store.
Stores the pairs in the key-value store, and returns itself. When a block is provided, it will be called before overwriting any existing values with the key, old value and supplied value, and the return value of the block will be used in place of the supplied value.
58 59 60 61 |
# File 'lib/moneta/adapters/leveldb.rb', line 58 def merge!(*keys, **) @backend.batch { super } self end |
#values_at(*keys, **options) ⇒ Array<Object, nil>
Some adapters may implement this method atomically, but the default implementation simply makes repeated calls to HashAdapter#load.
Returns an array containing the values associated with the given keys, in the same order as the supplied keys. If a key is not present in the key-value-store, nil is returned in its place.
51 52 53 54 55 |
# File 'lib/moneta/adapters/leveldb.rb', line 51 def values_at(*keys, **) ret = nil @backend.batch { ret = super } ret end |