• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
riak-js: Javascript Turtles All the Way Down
 

riak-js: Javascript Turtles All the Way Down

on

  • 7,303 views

riak-js is an awesome client driver for the Riak distributed datastore.

riak-js is an awesome client driver for the Riak distributed datastore.

Statistics

Views

Total Views
7,303
Views on SlideShare
7,176
Embed Views
127

Actions

Likes
13
Downloads
0
Comments
0

6 Embeds 127

http://lanyrd.com 81
http://coderwall.com 35
http://twitter.com 8
https://twitter.com 1
http://www.slideshare.net 1
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

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.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • Like all these turtles marching toward the sea, we’re on a path. And that path is the adoption of JavaScript in lots of places it hasn’t been before.\n
  • Like all these turtles marching toward the sea, we’re on a path. And that path is the adoption of JavaScript in lots of places it hasn’t been before.\n
  • Like all these turtles marching toward the sea, we’re on a path. And that path is the adoption of JavaScript in lots of places it hasn’t been before.\n
  • Like all these turtles marching toward the sea, we’re on a path. And that path is the adoption of JavaScript in lots of places it hasn’t been before.\n
  • So you’re probably saying “What about CouchDB? It has JavaScript”. \n\nCouchDB is great. I like it a lot. (apologies for the strawman) But it has been my experience that the types of applications people build on top of CouchDB are very different from the types of apps people build with Node.js. And you don’t want to end up like this turtle.\n\nYou want to be like these turtles!\n
  • So you’re probably saying “What about CouchDB? It has JavaScript”. \n\nCouchDB is great. I like it a lot. (apologies for the strawman) But it has been my experience that the types of applications people build on top of CouchDB are very different from the types of apps people build with Node.js. And you don’t want to end up like this turtle.\n\nYou want to be like these turtles!\n
  • So you’re probably saying “What about CouchDB? It has JavaScript”. \n\nCouchDB is great. I like it a lot. (apologies for the strawman) But it has been my experience that the types of applications people build on top of CouchDB are very different from the types of apps people build with Node.js. And you don’t want to end up like this turtle.\n\nYou want to be like these turtles!\n
  • So you’re probably saying “What about CouchDB? It has JavaScript”. \n\nCouchDB is great. I like it a lot. (apologies for the strawman) But it has been my experience that the types of applications people build on top of CouchDB are very different from the types of apps people build with Node.js. And you don’t want to end up like this turtle.\n\nYou want to be like these turtles!\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • * “Your data is safe with us.”\n* “Just add more machines.”\n* “Key-Value++, MapReduce, Search. With great power comes great responsibility - take ownership of your data.”\n
  • So if you want to work with Riak from node.js, Francisco Treacy wrote this awesome driver called riak-js. It’s also got a beautiful website at riakjs.org that is envy of all READMEs.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • Pretty much every API function takes a callback which receives the results - will be eliding the callback except where necessary.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Hosted on no.de\n
  • \n
  • \n
  • \n

riak-js: Javascript Turtles All the Way Down riak-js: Javascript Turtles All the Way Down Presentation Transcript

  • riak-jsJavaScript turtles all the way down Sean Cribbs http://whenchemistsattack.com/2008/04/25/turtles-all-the-way-down/
  • Browser Server DB
  • Browser JavaScript Java, Ruby, Server PHP, Python DB SQL
  • Browser JavaScript JavaScript Java, Ruby, Server node.js PHP, Python DB SQL SQL
  • Browser JavaScript JavaScript JavaScript Java, Ruby, Server node.js node.js PHP, Python DB SQL SQL JavaScript?!
  • Browser JavaScript JavaScript JavaScript Java, Ruby, Server node.js node.js PHP, Python DB SQL SQL JavaScript?! http://animals.nationalgeographic.com/animals/reptiles/kemps-ridley-sea-turtle/
  • What about Couch? It has JavaScript.
  • http://captainwildchild.blogspot.com/2011/04/stopping-for-turtles.htmlWhat about Couch? It has JavaScript.
  • http://www.comicbookmovie.com/teenage_mutant_ninja_turtles/news/?a=18553What about Couch? It has JavaScript.
  • What is Riak?
  • What is Riak?• Distributed, Fault-Tolerant, Replicated
  • What is Riak?• Distributed, Fault-Tolerant, Replicated• Scales out linearly
  • What is Riak?• Distributed, Fault-Tolerant, Replicated• Scales out linearly• Flexible data model
  • What is Riak?• Distributed, Fault-Tolerant, Replicated• Scales out linearly• Flexible data model
  • What is Riak? PLUS IPT!• Distributed, JAVASCR Fault-Tolerant, Replicated• Scales out linearly• Flexible data model
  • riakjs.org
  • Getting Started
  • Getting Started Install Riak or Riak Search:http://downloads.basho.com
  • Getting Started Install Riak or Riak Search: http://downloads.basho.com$ npm install riak-js@latest
  • Getting Started Install Riak or Riak Search: http://downloads.basho.com$ npm install riak-js@latest$ git clone git://github.com/frank06/riak-js
  • Getting Started Install Riak or Riak Search: http://downloads.basho.com$ npm install riak-js@latest$ git clone git://github.com/frank06/riak-js
  • Basic ClientOperations http://ijustwanttofitin.com/tag/rally-cars/
  • Basic Operations
  • Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()
  • Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an objectdb.get(conferences, nodeconf,  function(err, data) {    console.log("Found the conference:" + sys.inspect(data))  })
  • Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an object typical nodedb.get(conferences, nodeconf, callback style  function(err, data) {    console.log("Found the conference:" + sys.inspect(data))  })
  • Basic Operations// Get a client (pass options if needed)var db = require(riak-js).getClient()// Fetch an object typical nodedb.get(conferences, nodeconf, callback style  function(err, data) {    console.log("Found the conference:" + sys.inspect(data))  })// Store an objectdb.save(conferences, nodeconf,        {date:"2011-05-05",         title: "nodeconf 2011",         presenters: ["Sean Cribbs"]})
  • Basic Operations Picture: http://www.scooponpets.com/Turtlesaspets.html
  • Basic Operations// Delete an objectdb.remove(conferences, nodeconf) Picture: http://www.scooponpets.com/Turtlesaspets.html
  • Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master) Picture: http://www.scooponpets.com/Turtlesaspets.html
  • Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start() Picture: http://www.scooponpets.com/Turtlesaspets.html
  • Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start()// Give me them alldb.getAll(frameworks) Picture: http://www.scooponpets.com/Turtlesaspets.html
  • Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start()// Give me them alldb.getAll(frameworks) Picture: http://www.scooponpets.com/Turtlesaspets.html
  • Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start()// Give me them alldb.getAll(frameworks)// How many are there? (counts keys) Picture: http://www.scooponpets.com/Turtlesaspets.html
  • Basic Operations// Delete an objectdb.remove(conferences, nodeconf)// Does this key exist?db.exists(frameworks, node.js)// Stream the keys (on master)db.keys(frameworks,{keys:stream}). on(keys, cb).start()// Give me them alldb.getAll(frameworks)// How many are there? (counts keys)db.count(frameworks) Picture: http://www.scooponpets.com/Turtlesaspets.html
  • Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) function cb(err, data, META){ } Picture: http://chronotron.files.wordpress.com/2010/07/turtles.png
  • Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb)
  • Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata
  • Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata •contentType
  • Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata •contentType •clientId
  • Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata •contentType •clientId • links, usermeta
  • Meta Objectdb.save(‘bucket’, ‘key’, data, META, cb) • Request-time metadata •contentType •clientId • links, usermeta • quorums (r,w,dw), returnBody
  • Meta Objectfunction cb(err, data, META){ }
  • Meta Object function cb(err, data, META){ }• Response-time metadata
  • Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock
  • Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock • links, usermeta
  • Meta Object function cb(err, data, META){ }• Response-time metadata • bucket, key, vclock • links, usermeta • lastMod, etag, statusCode
  • Using Meta
  • Using Meta// Add a link to the objectdb.get(frameworks, node.js,  function(err, data, meta){    meta.addLink({bucket:vm, key:v8, tag:vm});    db.save(frameworks, node.js, data, meta)  })
  • Using Meta// Add a link to the objectdb.get(frameworks, node.js,  function(err, data, meta){    meta.addLink({bucket:vm, key:v8, tag:vm});    db.save(frameworks, node.js, data, meta)  })// Set the content typedb.save(pages, index.html,        <html><body>Hello, world!</body></html>,        {contentType: html})
  • Querying Beyond Key-Value Picture: http://greencs.files.wordpress.com/2008/07/turtle- nom.jpg
  • Link-walking Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al- aquarium.html
  • Link-walking// Find friendsdb.walk(people, sean, [[_,friend]]) Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al- aquarium.html
  • Link-walking// Find friendsdb.walk(people, sean, [[_,friend]])// Find acquaintances of friendsdb.walk(people, mathias,        [[_,friend], Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al- aquarium.html
  • Link-walking// Find friendsdb.walk(people, sean, [[_,friend]])// Find acquaintances of friendsdb.walk(people, mathias,        [[_,friend],         [people,_]]) Picture: http://fisherwy.blogspot.com/2007/09/two-headed-turtle-at-big-al- aquarium.html
  • Wait. You said Riakhad JavaScript in it! U MAD? Picture: http://arsnotoria.blogspot.com/2010_04_18_archive.html
  • MapReduce
  • MapReduce list of keys
  • MapReduce list of keysmap() map() map() map() map()
  • MapReduce list of keysmap() map() map() map() map() reduce()
  • MapReduce list of keysmap() map() map() map() map() reduce() results
  • MapReduce list of keys JSONmap() map() map() map() map() reduce() results
  • MapReduce list of keys JSON map() map() map() map() map()JavaScript JavaScript JavaScript JavaScript JavaScript reduce() results
  • MapReduce list of keys JSON map() map() map() map() map()JavaScript JavaScript JavaScript JavaScript JavaScript reduce() JavaScript results
  • MapReduce list of keys JSON map() map() map() map() map()JavaScript JavaScript JavaScript JavaScript JavaScript reduce() JavaScript results JSON
  • MapReduce
  • MapReduce// Execute a MapReduce querydb.add(frameworks) // Use all keys in bucket  .map(Riak.mapValuesJson) // Map using a built-in  .run(function(err, data){ // Execute the query         console.log(data);       })
  • MapReduce// Execute a MapReduce querydb.add(frameworks) // Use all keys in bucket  .map(Riak.mapValuesJson) // Map using a built-in  .run(function(err, data){ // Execute the query         console.log(data);       })// Send a focused querydb.add(frameworks, node.js) // Start with one key  .link({ bucket: "vm"}) // Follow some links  .map(function(obj){ // Map using an inline         var data =            Riak.mapValuesJson(obj)[0];         return [data.name]       })  .reduce(Riak.reduceSort) // Sort via reduce  .run()
  • MapReduce
  • MapReduce// Initiate MapReduce with a key-filterdb.add({ bucket: emails,         key_filters: [["ends_with", "basho.com"]] }) // Map with a phase-argument  .map({ name:Riak.mapByFields,         arg: { joined:2010-01-01 })  .run()
  • Riak Search
  • Riak Search// Turn on automatic document indexingdb.enableIndex(documents)
  • Riak Search// Turn on automatic document indexingdb.enableIndex(documents)// Perform a simple searchdb.search(documents, title:scalable)
  • Riak Search// Turn on automatic document indexingdb.enableIndex(documents)// Perform a simple searchdb.search(documents, title:scalable)// Start a MapReduce query with searchdb.addSearch(documents, title:scalable)// From here, add map and reduce phases
  • etc.
  • etc.• Session Store
  • etc.• Session Store• Mini-Riak Test Server
  • etc.• Session Store• Mini-Riak Test Server• Multi-protocol (HTTP, Protobuffs)
  • etc.• Session Store• Mini-Riak Test Server• Multi-protocol (HTTP, Protobuffs)• Luwak (large files)
  • COME AT ME BRO Picture: http://fl.biology.usgs.gov/posters/Herpetology/Snapping_Turtles/snapping_turtles.html Demo Timehttps://github.com/basho/riaktant
  • Questions?
  • Questions? sean@basho.com @seancribbs jsconf.basho.com
  • Riak on Turtles (someday)Picture: http://scienceblogs.com/bioephemera/2008/07/gpsequipped_box_turtle_leads_p.php