Class: Moneta::Adapters::Riak
- Inherits:
-
Moneta::Adapter
- Object
- Moneta::Adapter
- Moneta::Adapters::Riak
- Defined in:
- lib/moneta/adapters/riak.rb
Overview
Riak backend
Instance Attribute Summary
Attributes inherited from Moneta::Adapter
Instance Method Summary collapse
-
#clear(options = {}) ⇒ void
Clear all keys in this store.
-
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value.
-
#initialize(options = {}) ⇒ Riak
constructor
A new instance of Riak.
-
#key?(key, options = {}) ⇒ Boolean
Exists the value with key.
-
#load(key, options = {}) ⇒ Object
Fetch value with key.
-
#store(key, value, options = {}) ⇒ Object
Store value with key.
Methods inherited from Moneta::Adapter
backend, backend_block, backend_required?
Methods included from Config
Methods included from Defaults
#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #increment, #merge!, #slice, #supports?, #update, #values_at
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Riak
Returns a new instance of Riak.
19 20 21 22 |
# File 'lib/moneta/adapters/riak.rb', line 19 def initialize( = {}) super @bucket = backend.bucket(config.bucket) end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
53 54 55 56 57 58 |
# File 'lib/moneta/adapters/riak.rb', line 53 def clear( = {}) @bucket.keys do |keys| keys.each { |key| @bucket.delete(key) } end self end |
#delete(key, options = {}) ⇒ Object
Delete the key from the store and return the current value
37 38 39 40 41 |
# File 'lib/moneta/adapters/riak.rb', line 37 def delete(key, = {}) value = load(key, ) @bucket.delete(key, .dup) value end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
25 26 27 |
# File 'lib/moneta/adapters/riak.rb', line 25 def key?(key, = {}) @bucket.exists?(key, .dup) end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
30 31 32 33 34 |
# File 'lib/moneta/adapters/riak.rb', line 30 def load(key, = {}) @bucket.get(key, .dup).raw_data rescue ::Riak::FailedRequest nil end |
#store(key, value, options = {}) ⇒ Object
Store value with key
44 45 46 47 48 49 50 |
# File 'lib/moneta/adapters/riak.rb', line 44 def store(key, value, = {}) obj = ::Riak::RObject.new(@bucket, key) obj.content_type = [:content_type] || config.content_type obj.raw_data = value obj.store(.dup) value end |