Module: Adapter::Riak
- Defined in:
- lib/adapter/riak.rb,
lib/adapter/riak/version.rb,
lib/adapter/riak/conflict.rb
Defined Under Namespace
Classes: Conflict
Constant Summary collapse
- VERSION =
"0.5"
Instance Method Summary collapse
- #clear ⇒ Object
- #decode(value) ⇒ Object
- #delete(key) ⇒ Object
- #encode(value) ⇒ Object
-
#key?(key) ⇒ Boolean
Optimize key? to do head request in riak instead of full key read and nil check.
- #read(key) ⇒ Object
- #write(key, value) ⇒ Object
Instance Method Details
#clear ⇒ Object
37 38 39 40 41 |
# File 'lib/adapter/riak.rb', line 37 def clear client.keys do |keys| keys.each { |key| client.delete(key) } end end |
#decode(value) ⇒ Object
47 48 49 |
# File 'lib/adapter/riak.rb', line 47 def decode(value) value end |
#delete(key) ⇒ Object
33 34 35 |
# File 'lib/adapter/riak.rb', line 33 def delete(key) read(key).tap { client.delete(key_for(key)) } end |
#encode(value) ⇒ Object
43 44 45 |
# File 'lib/adapter/riak.rb', line 43 def encode(value) value end |
#key?(key) ⇒ Boolean
Optimize key? to do head request in riak instead of full key read and nil check
12 13 14 |
# File 'lib/adapter/riak.rb', line 12 def key?(key) client.exists?(key_for(key)) end |
#read(key) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/adapter/riak.rb', line 16 def read(key) robject = client.get(key_for(key)) raise Conflict.new(robject) if robject.conflict? robject.data rescue ::Riak::FailedRequest => e e.code.to_i == 404 ? nil : raise(e) end |
#write(key, value) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/adapter/riak.rb', line 24 def write(key, value) key = key_for(key) obj = client.get_or_new(key) obj.content_type = 'application/json' obj.data = value obj.store value end |