Class: Moneta::Adapters::Riak
- Inherits:
-
Object
- Object
- Moneta::Adapters::Riak
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/riak.rb
Overview
Riak backend
Instance Attribute Summary collapse
- #backend ⇒ Object readonly
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 included from Defaults
#[], #[]=, #close, #create, #decrement, #features, #fetch, included, #increment, #supports?
Methods included from OptionSupport
#expires, #prefix, #raw, #with
Constructor Details
#initialize(options = {}) ⇒ Riak
Returns a new instance of Riak.
20 21 22 23 24 25 |
# File 'lib/moneta/adapters/riak.rb', line 20 def initialize( = {}) bucket = .delete(:bucket) || 'moneta' @content_type = .delete(:content_type) || 'application/octet-stream' @backend = [:backend] || ::Riak::Client.new() @bucket = @backend.bucket(bucket) end |
Instance Attribute Details
#backend ⇒ Object (readonly)
13 14 15 |
# File 'lib/moneta/adapters/riak.rb', line 13 def backend @backend end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
56 57 58 59 60 61 |
# File 'lib/moneta/adapters/riak.rb', line 56 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
40 41 42 43 44 |
# File 'lib/moneta/adapters/riak.rb', line 40 def delete(key, = {}) value = load(key, ) @bucket.delete(key, .dup) value end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
28 29 30 |
# File 'lib/moneta/adapters/riak.rb', line 28 def key?(key, = {}) @bucket.exists?(key, .dup) end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
33 34 35 36 37 |
# File 'lib/moneta/adapters/riak.rb', line 33 def load(key, = {}) @bucket.get(key, .dup).raw_data rescue ::Riak::FailedRequest => ex nil end |
#store(key, value, options = {}) ⇒ Object
Store value with key
47 48 49 50 51 52 53 |
# File 'lib/moneta/adapters/riak.rb', line 47 def store(key, value, = {}) obj = ::Riak::RObject.new(@bucket, key) obj.content_type = [:content_type] || @content_type obj.raw_data = value obj.store(.dup) value end |