-
Notifications
You must be signed in to change notification settings - Fork 152
Home
bluehavana edited this page Aug 13, 2010
·
18 revisions
Ripple is a rich Ruby client for Riak, Basho’s distributed database. It includes two namespaces:
-
Riak
contains a basic wrapper around typical operations, including bucket manipulation, object CRUD, link-walking, and map-reduce. -
Ripple
contains an ActiveModel-compatible modeling layer that is inspired by ActiveRecord, DataMapper, and MongoMapper.
gem install ripple
Or git clone git://github.com/seancribbs/ripple.git
require 'riak'
# Create a client interface client = Riak::Client.new
# Retrieve a bucket bucket = client.bucket("doc") # a Riak::Bucket
# Get an object from the bucket object = bucket.get("index.html") # a Riak::RObject
# Change the object's data and save object.data = "Hello, world!" 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
# Assuming you've already instantiated a client, get the album titles for The Beatles results = Riak::MapReduce.new(client). add("artists","Beatles"). link(:bucket => "albums"). map("function(v){ return [JSON.parse(v.values[0].data).title]; }", :keep => true).run
p results # => ["Please Please Me", "With The Beatles", "A Hard Day's Night", # "Beatles For Sale", "Help!", "Rubber Soul", # "Revolver", "Sgt. Pepper's Lonely Hearts Club Band", "Magical Mystery Tour", # "The Beatles", "Yellow Submarine", "Abbey Road", "Let It Be"]