Ruby on Rails is a powerful web framework that focuses on developer productivity. Riak is a friendly key-value store that is simple, flexible and scalable. Put them together and you have lots of exciting possibilities!
7. require ‘riak’
Make a client object
client = Riak::Client.new # or Ripple.client
Get a bucket
bucket = client.bucket(‘foo’) # Riak::Bucket
Get an object from the bucket
obj = bucket.get(‘bar’) # Riak::RObject
Initialize a new object
obj = bucket.new(‘baz’)
basho
8. Riak::RObject
Get/set object key
obj.key = “bar”
Get/set content-type
obj.content_type = ‘application/json’
Get/set the object body data (JSON auto enc/dec)
obj.data = {“name” => “Sean”}
Store the object
obj.store
basho
9. Using Links
Create a link
Riak::Link.new(“/riak/bucket/key”, “tag”)
Read an object’s links
obj.links # Set<Riak::Link>
Convert an object to a link
obj.links << obj2.to_link(“next”)
obj.store
basho
10. Link-Walking
obj = client[‘demo’][‘test1’]
obj.walk(:keep => true)
# Get all linked one-level
obj.walk(:bucket => “demo”, :keep => true)
# Get all linked in “demo” bucket
obj.walk(:tag => ‘friend’, :keep => true)
# Get all linked with tag “friend”
obj.walk({},{:keep => true})
# Get all linked at second level
basho
14. Riak as Document DB
Store semi-structured data as “documents” (JSON)
Alternative to CouchDB or MongoDB
Links and Link-walking for easy relationships
MapReduce for more involved queries
basho
22. Riak as a Cache Store
It’s a K/V store - similar to memcached, redis
Flexible serialization options: JSON, YAML, Marshal,
text, binary
Tune for performance over consistency
Low quorums and replication
Last-write-wins?
In-memory backend
basho
23. Using Riak::CacheStore
Implements ActiveSupport::Cache::Store
Sets quorum/n_val defaults for you (tweakable)
R=W=RW=1, DW=0, N=2
Doesn’t set backend or last_write_wins (tweakable)
config.cache_store = :riak_store
basho
24. Caveats
Not as fast as memcached or redis
No per-object expiry (could be done client-side)
basho
27. Riak as a Session store
Substitute for ActiveRecord or memcached sessions
Use when you need larger or longer-lived sessions
Tune for modest durability and performance
Low quorums, modest N (2 or 3)
Fast disk backend (bitcask) or memory (ets)
basho
28. Ripple::SessionStore (WIP)
Sets quorum/n_val defaults for you
Implements ActionDispatch::Session::AbstractStore
config.session_store = ::Riak::SessionStore
Coming in next release of Ripple (0.8.0)
basho
30. Riak with Rails
Useful in many contexts
Semi-structured data/documents
Web-friendly storage
Distributed cache / session storage
Flexible K/V storage
Grows with your app
basho
31. Ripple Roadmap
Testing assistance/automation
Protocol buffers interface, HTTP enhancements
More association types
Get involved: http://github.com/seancribbs/ripple
basho
32. Plug
Interested in learning about support, consulting, or
Enterprise features?
Email info@basho.com or go to
http://www.basho.com/contact.html to talk with us.
www.basho.com
basho
33. Plug
Interested in learning about support, consulting, or
Enterprise features?
Email info@basho.com or go to
http://www.basho.com/contact.html to talk with us.
www.basho.com
sean@basho.com
@seancribbs
basho