Class: Juno::Adapters::Riak
Overview
Riak backend
Instance Method Summary collapse
- #clear(options = {}) ⇒ Object
- #delete(key, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Riak
constructor
Constructor.
- #key?(key, options = {}) ⇒ Boolean
- #load(key, options = {}) ⇒ Object
- #store(key, value, options = {}) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Riak
Constructor
Options:
-
:bucket - Bucket name (default juno)
-
:content_type - Default content type (default application/octet-stream)
-
All other options passed to Riak::Client#new
19 20 21 22 23 |
# File 'lib/juno/adapters/riak.rb', line 19 def initialize( = {}) bucket = .delete(:bucket) || 'juno' @content_type = .delete(:content_type) || 'application/octet-stream' @bucket = ::Riak::Client.new().bucket(bucket) end |
Instance Method Details
#clear(options = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/juno/adapters/riak.rb', line 49 def clear( = {}) @bucket.keys do |keys| keys.each{ |key| @bucket.delete(key) } end self end |
#delete(key, options = {}) ⇒ Object
35 36 37 38 39 |
# File 'lib/juno/adapters/riak.rb', line 35 def delete(key, = {}) value = load(key, ) @bucket.delete(key, ) value end |
#key?(key, options = {}) ⇒ Boolean
25 26 27 |
# File 'lib/juno/adapters/riak.rb', line 25 def key?(key, = {}) @bucket.exists?(key, ) end |
#load(key, options = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/juno/adapters/riak.rb', line 29 def load(key, = {}) @bucket.get(key, ).raw_data rescue ::Riak::FailedRequest => ex nil end |
#store(key, value, options = {}) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/juno/adapters/riak.rb', line 41 def store(key, value, = {}) obj = ::Riak::RObject.new(@bucket, key) obj.content_type = [:content_type] || @content_type obj.raw_data = value obj.store() value end |