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, #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.
18 19 20 21 22 23 |
# File 'lib/moneta/adapters/riak.rb', line 18 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)
11 12 13 |
# File 'lib/moneta/adapters/riak.rb', line 11 def backend @backend end |
Instance Method Details
#clear(options = {}) ⇒ void
This method returns an undefined value.
Clear all keys in this store
54 55 56 57 58 59 |
# File 'lib/moneta/adapters/riak.rb', line 54 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
38 39 40 41 42 |
# File 'lib/moneta/adapters/riak.rb', line 38 def delete(key, = {}) value = load(key, ) @bucket.delete(key, .dup) value end |
#key?(key, options = {}) ⇒ Boolean
Exists the value with key
26 27 28 |
# File 'lib/moneta/adapters/riak.rb', line 26 def key?(key, = {}) @bucket.exists?(key, .dup) end |
#load(key, options = {}) ⇒ Object
Fetch value with key. Return nil if the key doesn’t exist
31 32 33 34 35 |
# File 'lib/moneta/adapters/riak.rb', line 31 def load(key, = {}) @bucket.get(key, .dup).raw_data rescue ::Riak::FailedRequest nil end |
#store(key, value, options = {}) ⇒ Object
Store value with key
45 46 47 48 49 50 51 |
# File 'lib/moneta/adapters/riak.rb', line 45 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 |