Class: RiakRaw::Client
- Inherits:
-
Object
- Object
- RiakRaw::Client
- Defined in:
- lib/riak_raw.rb
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
- #bucket(bucket_name, keys = false) ⇒ Object
-
#delete(bucket_name, key, dw = 2) ⇒ Object
there could be concurrency issues if we don’t force a short sleep after delete.
- #fetch(bucket_name, key, _params = {}) ⇒ Object
-
#initialize(host = "127.0.0.1", port = 8098, prefix = 'riak', client_id = SecureRandom.base64) ⇒ Client
constructor
A new instance of Client.
- #set_bucket_properties(name, props) ⇒ Object
- #store(bucket_name, key, content, vclock = nil, links = [], content_type = 'application/json', w = 2, dw = 2, r = 2) ⇒ Object
Constructor Details
#initialize(host = "127.0.0.1", port = 8098, prefix = 'riak', client_id = SecureRandom.base64) ⇒ Client
Returns a new instance of Client.
23 24 25 26 27 28 |
# File 'lib/riak_raw.rb', line 23 def initialize(host="127.0.0.1", port=8098, prefix='riak', client_id=SecureRandom.base64) @host = host @port = port @prefix = prefix @client_id = client_id end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
21 22 23 |
# File 'lib/riak_raw.rb', line 21 def client_id @client_id end |
#host ⇒ Object
Returns the value of attribute host.
21 22 23 |
# File 'lib/riak_raw.rb', line 21 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
21 22 23 |
# File 'lib/riak_raw.rb', line 21 def port @port end |
#prefix ⇒ Object
Returns the value of attribute prefix.
21 22 23 |
# File 'lib/riak_raw.rb', line 21 def prefix @prefix end |
Instance Method Details
#bucket(bucket_name, keys = false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/riak_raw.rb', line 30 def bucket(bucket_name,keys=false) #request(:get, build_path(bucket_name)) response = request(:get, build_path(bucket_name), nil, nil, {"returnbody" => "true", "keys" => keys}) if response.code == 200 if json = response.body return Yajl::Parser.parse(json) end end; nil end |
#delete(bucket_name, key, dw = 2) ⇒ Object
there could be concurrency issues if we don’t force a short sleep after delete. see: issues.basho.com/show_bug.cgi?id=52
81 82 83 84 85 |
# File 'lib/riak_raw.rb', line 81 def delete(bucket_name, key, dw=2) response = request(:delete, build_path(bucket_name, key), nil, {}, {"dw" => dw}) end |
#fetch(bucket_name, key, _params = {}) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/riak_raw.rb', line 70 def fetch(bucket_name, key, _params={}) params = {} _params.each { |k,v| params[k.to_s] = v } params["r"] ||= 2 response = request(:get, build_path(bucket_name, key), nil, {}, params) end |
#set_bucket_properties(name, props) ⇒ Object
43 44 45 46 47 |
# File 'lib/riak_raw.rb', line 43 def set_bucket_properties(name,props) response = request(:put, build_path(name), Yajl::Encoder.encode(props), { 'Content-Type' => 'application/json' }) end |
#store(bucket_name, key, content, vclock = nil, links = [], content_type = 'application/json', w = 2, dw = 2, r = 2) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/riak_raw.rb', line 49 def store(bucket_name, key, content, vclock=nil, links=[], content_type='application/json', w=2, dw=2, r=2) headers = { 'Content-Type' => content_type, 'X-Riak-ClientId' => self.client_id } if vclock headers['X-Riak-Vclock'] = vclock end response = request(:put, build_path(bucket_name,key), content, headers, {"returnbody" => "false", "w" => w, "dw" => dw}) # returnbody=true could cause issues. instead we'll do a # separate fetch. see: https://issues.basho.com/show_bug.cgi?id=52 if response.code == 204 response = fetch(bucket_name, key, {:r => r}) end response end |