Your SlideShare is downloading. ×
Riak Intro at Munich Node.js
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Riak Intro at Munich Node.js

1,010
views

Published on

Introduction to Riak, riak-js and MapReduce at Munich node.js user group

Introduction to Riak, riak-js and MapReduce at Munich node.js user group

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,010
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Riak and Node.js: Best served with HTTP Philipp Fehre https://github.com/sideshowcoder
  • 2. What is Riak? A Key Value store A Dynamo store!
  • 3. Distributed
  • 4. Replicated
  • 5. Fault tolerant
  • 6. Scaling Basically means add more machines
  • 7. Gains more storage more throughput lower latency
  • 8. And it is Web friendly HTTP Interface Value is irrelevant so you can store JSON Support for JavaScript functions
  • 9. When to use Riak
  • 10. Data Organization keys identify objects objects have metadata objects are grouped into buckets
  • 11. More Data Features Links Secoundary indexes Timeouts
  • 12. HTTP Riak understands simple HTTP
  • 13. Create some data curl -v -XPUT http://localhost:8098/riak/test/doc -H "Content-Type: application/json" -d '{"bar":"baz"}'
  • 14. Query by key curl -v http://localhost:8098/riak/test/doc
  • 15. Everything can be done via HTTP
  • 16. like setting properties of the bucket curl -v -XPUT -H "Content-Type: application/json" -d '{"props":{"n_val":5}}'
  • 17. or MapReduce curl -XPOST http://localhost:8098/mapred -H 'Content-Type: application/json' -d '{ "inputs":"training", "query":[{"map":{"language":"javascript", "source":"function(riakObject) { var val = riakObject.values[0].data.match(/pizza/g); return [[riakObject.key, (val ? val.length : 0)]]; }"}}]}'
  • 18. Ok but we do JavaScript
  • 19. ... or more like Node
  • 20. Using Riak from Node
  • 21. JavaScript all the way down if you want it to be!
  • 22. The Client var db = require("riak-js").getClient()
  • 23. Store an Object var obj = { val: "foo", bar: true } db.save("foos", "foo_1", obj, {}, function(err) { if(!err) console.log("stored") })
  • 24. Retrieve an Object db.get("foos", "foo_1", function(err, data, meta) { if(!err) { console.log(data) console.log(meta) } })
  • 25. Map and Reduce "MapReduce is a programming model for processing large data sets with a parallel, distributed algorithm on a cluster" -Wikipedia
  • 26. Riak MapReduce Queries provide a set of keys provide a map function provide a reduce function
  • 27. Select Keys db.mapreduce.add("foos")
  • 28. var key_filter = [["tokenize", "_", 1], ["to_lower"], ["matches", "foo"]] db.mapreduce.add({ bucket: "foos", key_filters: key_filter })
  • 29. Map a buildin db.mapreduce .add("foos") .map({ name: 'Riak.mapValueJson', keep: true }) .run()
  • 30. Map custom function var func = function(v, _keyData, arg) { var v = Riak.mapValuesJson(v)[0]; (v.val === "foo") ? return [v] : return []; } db.mapreduce.add("foos").map(func).run()
  • 31. Reduce with custom var func = function(values) { return [ values.length ] } db.mapreduce... .reduce(func) .run()
  • 32. A little more complex function(values) { return values.reduce(function(acc, v) { if(v.bar) { var curr = acc["bar"] || 0 acc["bar"] = curr + 1 } return acc; }) }
  • 33. Questions · Usergroup: www.meetup.com/Riak-Munchen/ · More on the basics: littleriakbook.com

×