Class: Moneta::Adapters::Riak
- Inherits:
-
Object
- Object
- Moneta::Adapters::Riak
- Includes:
- Defaults
- Defined in:
- lib/moneta/adapters/riak.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
-
#initialize(options = {}) ⇒ Riak
constructor
A new instance of Riak.
- #key?(key) ⇒ Boolean
- #store(key, value) ⇒ Object
Methods included from Defaults
Constructor Details
#initialize(options = {}) ⇒ Riak
Returns a new instance of Riak.
16 17 18 19 20 |
# File 'lib/moneta/adapters/riak.rb', line 16 def initialize( = {}) bucket_name = .delete(:bucket) || 'moneta' client = ::Riak::Client.new() @bucket = client.bucket(bucket_name) end |
Instance Method Details
#[](key) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/moneta/adapters/riak.rb', line 26 def [](key) serialized_key = key_for(key) deserialize(@bucket[serialized_key].data) rescue ::Riak::HTTPFailedRequest => err nil end |
#clear ⇒ Object
48 49 50 |
# File 'lib/moneta/adapters/riak.rb', line 48 def clear(*) @bucket.keys.each{|key| @bucket.delete(key)} end |
#delete(key) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/moneta/adapters/riak.rb', line 33 def delete(key, *) value = self[key] serialized_key = key_for(key) @bucket.delete(serialized_key) value end |
#key?(key) ⇒ Boolean
22 23 24 |
# File 'lib/moneta/adapters/riak.rb', line 22 def key?(key, *) !!self[key] end |
#store(key, value) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/moneta/adapters/riak.rb', line 40 def store(key, value, *) serialized_key = key_for(key) obj = ::Riak::RObject.new(@bucket, serialized_key) obj.content_type = "text/plain" obj.data = serialize(value) obj.store end |