Riak Intro at Munich Node.js
Upcoming SlideShare
Loading in...5

Riak Intro at Munich Node.js



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



Total Views
Views on SlideShare
Embed Views



4 Embeds 335

http://sideshowcoder.com 326
http://www.newsblur.com 4
http://newsblur.com 4
http://cloud.feedly.com 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Riak Intro at Munich Node.js Riak Intro at Munich Node.js Presentation Transcript

  • Riak and Node.js: Best served with HTTP Philipp Fehre https://github.com/sideshowcoder
  • What is Riak? A Key Value store A Dynamo store!
  • Distributed
  • Replicated
  • Fault tolerant
  • Scaling Basically means add more machines
  • Gains more storage more throughput lower latency
  • And it is Web friendly HTTP Interface Value is irrelevant so you can store JSON Support for JavaScript functions
  • When to use Riak
  • Data Organization keys identify objects objects have metadata objects are grouped into buckets
  • More Data Features Links Secoundary indexes Timeouts
  • HTTP Riak understands simple HTTP
  • Create some data curl -v -XPUT http://localhost:8098/riak/test/doc -H "Content-Type: application/json" -d '{"bar":"baz"}'
  • Query by key curl -v http://localhost:8098/riak/test/doc
  • Everything can be done via HTTP
  • like setting properties of the bucket curl -v -XPUT -H "Content-Type: application/json" -d '{"props":{"n_val":5}}'
  • 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)]]; }"}}]}'
  • Ok but we do JavaScript
  • ... or more like Node
  • Using Riak from Node
  • JavaScript all the way down if you want it to be!
  • The Client var db = require("riak-js").getClient()
  • Store an Object var obj = { val: "foo", bar: true } db.save("foos", "foo_1", obj, {}, function(err) { if(!err) console.log("stored") })
  • Retrieve an Object db.get("foos", "foo_1", function(err, data, meta) { if(!err) { console.log(data) console.log(meta) } })
  • Map and Reduce "MapReduce is a programming model for processing large data sets with a parallel, distributed algorithm on a cluster" -Wikipedia
  • Riak MapReduce Queries provide a set of keys provide a map function provide a reduce function
  • Select Keys db.mapreduce.add("foos")
  • var key_filter = [["tokenize", "_", 1], ["to_lower"], ["matches", "foo"]] db.mapreduce.add({ bucket: "foos", key_filters: key_filter })
  • Map a buildin db.mapreduce .add("foos") .map({ name: 'Riak.mapValueJson', keep: true }) .run()
  • 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()
  • Reduce with custom var func = function(values) { return [ values.length ] } db.mapreduce... .reduce(func) .run()
  • 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; }) }
  • Questions · Usergroup: www.meetup.com/Riak-Munchen/ · More on the basics: littleriakbook.com