Created
August 8, 2011 21:24
-
-
Save bretthoerner/1132788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'riak' | |
# Create a client interface | |
# client = Riak::Client.new | |
# Create a client interface that uses Excon | |
# client = Riak::Client.new(:http_backend => :Excon) | |
# Create a client that uses Protocol Buffers | |
client = Riak::Client.new(:protocol => "pbc") | |
# Retrieve a bucket | |
bucket = client.bucket("doc") # a Riak::Bucket | |
# Get an object from the bucket | |
object = bucket.get("index.html") # a Riak::RObject | |
# /home/brett/.rvm/gems/ruby-1.9.2-p290/gems/riak-client-0.9.7/lib/riak/client/beefcake_protobuffs_backend.rb:152:in `decode_response': Expected success from Riak but received not_found. The requested object was not found. (Riak::ProtobuffsFailedRequest) | |
# from /home/brett/.rvm/gems/ruby-1.9.2-p290/gems/riak-client-0.9.7/lib/riak/client/beefcake_protobuffs_backend.rb:52:in `fetch_object' | |
# from /home/brett/.rvm/gems/ruby-1.9.2-p290/gems/riak-client-0.9.7/lib/riak/bucket.rb:102:in `get' | |
# from Desktop/foo.rb:16:in `<main>' | |
# Change the object's data and save | |
object.data = "<html><body>Hello, world!</body></html>" | |
object.store | |
# Reload an object you already have | |
object.reload # Works if you have the key and vclock, using conditional GET | |
object.reload :force => true # Reloads whether you have the vclock or not | |
# Access more like a hash, client[bucket][key] | |
client['doc']['index.html'] # the Riak::RObject | |
# Create a new object | |
new_one = Riak::RObject.new(bucket, "application.js") | |
new_one.content_type = "application/javascript" # You must set the content type. | |
new_one.data = "alert('Hello, World!')" | |
new_one.store |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment