0
Riak with node.js         Sean Cribbs   Mathias Meyer             Developer Advocatesbasho
Upcoming Events        Mark Phillips, Community Manager        mark@basho.com @pharkmillupsbasho
Why Riak with node.js?basho
Why Riak with node.js?        • Simple to understand and usebasho
Why Riak with node.js?        • Simple to understand and use        • Flexible storage optionsbasho
Why Riak with node.js?        • Simple to understand and use        • Flexible storage options        • Awesome client lib...
Why Riak with node.js?        • Simple to understand and use        • Flexible storage options        • Awesome client lib...
Getting Startedbasho
Getting Started         Install Riak or Riak Search:        http://downloads.basho.combasho
Getting Started            Install Riak or Riak Search:           http://downloads.basho.com        $ npm install riak-jsb...
Getting Started            Install Riak or Riak Search:           http://downloads.basho.com        $ npm install riak-js ...
Getting Started            Install Riak or Riak Search:           http://downloads.basho.com        $ npm install riak-js ...
Basic Client        Operationsbasho
Basic Operationsbasho
Basic Operations        // Get a client        var db = require(riak-js).getClient()basho
Basic Operations        // Get a client        var db = require(riak-js).getClient()        // Fetch an object        db.g...
Basic Operations        // Get a client        var db = require(riak-js).getClient()        // Fetch an object            ...
Basic Operations        // Get a client        var db = require(riak-js).getClient()        // Fetch an object            ...
Basic Operationsbasho
Basic Operations        // Delete an object        db.remove(webinars, node.js)basho
Basic Operations        // Delete an object        db.remove(webinars, node.js)        // Does this key exist?        db.e...
Basic Operations        // Delete an object        db.remove(webinars, node.js)        // Does this key exist?        db.e...
Basic Operations        // Delete an object        db.remove(webinars, node.js)        // Does this key exist?        db.e...
Basic Operations        // Delete an object        db.remove(webinars, node.js)        // Does this key exist?        db.e...
Meta Object    db.save(‘bucket’, ‘key’, data, META, cb)        function cb(err, data, META){ }basho
Meta Object    db.save(‘bucket’, ‘key’, data, META, cb)basho
Meta Object    db.save(‘bucket’, ‘key’, data, META, cb)        • Request-time optionsbasho
Meta Object    db.save(‘bucket’, ‘key’, data, META, cb)        • Request-time options         •contentTypebasho
Meta Object    db.save(‘bucket’, ‘key’, data, META, cb)        • Request-time options         •contentType         •client...
Meta Object    db.save(‘bucket’, ‘key’, data, META, cb)        • Request-time options         •contentType         •client...
Meta Object    db.save(‘bucket’, ‘key’, data, META, cb)        • Request-time options         •contentType         •client...
Meta Object        function cb(err, data, META){ }basho
Meta Object         function cb(err, data, META){ }        • Response-time metadatabasho
Meta Object         function cb(err, data, META){ }        • Response-time metadata         • bucket, key, vclockbasho
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         ...
Using Metabasho
Using Meta        // Add a link to the object        db.get(frameworks, node.js,          function(err, data, meta){      ...
Using Meta        // Add a link to the object        db.get(frameworks, node.js,          function(err, data, meta){      ...
Querying Beyond          Key-Valuebasho
Link-walkingbasho
Link-walking        // Find friends        db.walk(people, sean, [[_,friend]])basho
Link-walking        // Find friends        db.walk(people, sean, [[_,friend]])        // Find acquaintances of friends    ...
MapReducebasho
MapReduce        // Execute a MapReduce query        db.add(frameworks)         // Use all keys in bucket          .map(Ri...
MapReduce        // Execute a MapReduce query        db.add(frameworks)         // Use all keys in bucket          .map(Ri...
MapReducebasho
MapReduce        // Initiate MapReduce with a key-filter        db.add({ bucket: emails,                 key_filters: [["e...
Riak Searchbasho
Riak Search        // Turn on automatic document indexing        db.enableIndex(documents)basho
Riak Search        // Turn on automatic document indexing        db.enableIndex(documents)        // Perform a simple sear...
Riak Search        // Turn on automatic document indexing        db.enableIndex(documents)        // Perform a simple sear...
Running Testsbasho
Test Serverbasho
Test Server        // Add test server to your tests        var TestServer = require(riak-js).TestServerbasho
Test Server        // Add test server to your tests        var TestServer = require(riak-js).TestServer        var testSer...
Test Server        // Add test server to your tests        var TestServer = require(riak-js).TestServer        var testSer...
Test Server        // Add test server to your tests        var TestServer = require(riak-js).TestServer        var testSer...
Test Server        // Add test server to your tests        var TestServer = require(riak-js).TestServer        var testSer...
Test Server        // Add test server to your tests        var TestServer = require(riak-js).TestServer        var testSer...
Test Serverbasho
Test Server        // Clear data before a test        suite.addBatch({          stores data:{             topic: function(...
Test Server        // Clear data before a test        suite.addBatch({          stores data:{             topic: function(...
Demo & Code        https://github.com/basho/riaktantbasho
Hosted on Joyent                               http://no.de           Demo & Code        https://github.com/basho/riaktant...
Plug        Interested in learning about support,        consulting, or Enterprise features?        Email info@basho.com o...
Plug        Interested in learning about support,        consulting, or Enterprise features?        Email info@basho.com o...
Questions?basho
Upcoming SlideShare
Loading in...5
×

Riak with node.js

11,672

Published on

Learn how to use Riak with node.js applications.

Published in: Technology
0 Comments
11 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
11,672
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
118
Comments
0
Likes
11
Embeds 0
No embeds

No notes for slide
  • \n
  • Erlang Factory SF Bay next week - Free Erlounge Thursday night\nSponsoring JSConf and NodeConf May 1-5\nPossible Riak hackathon in PDX, contact Mark about any events\n
  • * Key-value API, mostly, over HTTP\n* key-value, search, large files || RAM, disk\n* riak-js rules\n* Demo will show a write-heavy app\n
  • * Key-value API, mostly, over HTTP\n* key-value, search, large files || RAM, disk\n* riak-js rules\n* Demo will show a write-heavy app\n
  • * Key-value API, mostly, over HTTP\n* key-value, search, large files || RAM, disk\n* riak-js rules\n* Demo will show a write-heavy app\n
  • * Key-value API, mostly, over HTTP\n* key-value, search, large files || RAM, disk\n* riak-js rules\n* Demo will show a write-heavy app\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
  • \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
  • Transcript of "Riak with node.js"

    1. 1. Riak with node.js Sean Cribbs Mathias Meyer Developer Advocatesbasho
    2. 2. Upcoming Events Mark Phillips, Community Manager mark@basho.com @pharkmillupsbasho
    3. 3. Why Riak with node.js?basho
    4. 4. Why Riak with node.js? • Simple to understand and usebasho
    5. 5. Why Riak with node.js? • Simple to understand and use • Flexible storage optionsbasho
    6. 6. Why Riak with node.js? • Simple to understand and use • Flexible storage options • Awesome client library (riak-js)basho
    7. 7. Why Riak with node.js? • Simple to understand and use • Flexible storage options • Awesome client library (riak-js) • Fits lots of use-casesbasho
    8. 8. Getting Startedbasho
    9. 9. Getting Started Install Riak or Riak Search: http://downloads.basho.combasho
    10. 10. Getting Started Install Riak or Riak Search: http://downloads.basho.com $ npm install riak-jsbasho
    11. 11. Getting Started Install Riak or Riak Search: http://downloads.basho.com $ npm install riak-js $ git clone git://github.com/frank06/riak-jsbasho
    12. 12. Getting Started Install Riak or Riak Search: http://downloads.basho.com $ npm install riak-js $ git clone git://github.com/frank06/riak-js Website: http://riakjs.orgbasho
    13. 13. Basic Client Operationsbasho
    14. 14. Basic Operationsbasho
    15. 15. Basic Operations // Get a client var db = require(riak-js).getClient()basho
    16. 16. Basic Operations // Get a client var db = require(riak-js).getClient() // Fetch an object db.get(webinars, node.js,   function(err, data) {     console.log("Found the webinar:" + sys.inspect(data))   })basho
    17. 17. Basic Operations // Get a client var db = require(riak-js).getClient() // Fetch an object typical node db.get(webinars, node.js, callback style   function(err, data) {     console.log("Found the webinar:" + sys.inspect(data))   })basho
    18. 18. Basic Operations // Get a client var db = require(riak-js).getClient() // Fetch an object typical node db.get(webinars, node.js, callback style   function(err, data) {     console.log("Found the webinar:" + sys.inspect(data))   }) // Store an object db.save(webinars, node.js,         {date:"2011-03-15",          title: "Riak with node.js",          presenters: ["Sean", "Mathias"]})basho
    19. 19. Basic Operationsbasho
    20. 20. Basic Operations // Delete an object db.remove(webinars, node.js)basho
    21. 21. Basic Operations // Delete an object db.remove(webinars, node.js) // Does this key exist? db.exists(frameworks, node.js)basho
    22. 22. Basic Operations // Delete an object db.remove(webinars, node.js) // Does this key exist? db.exists(frameworks, node.js) // Give me them all db.getAll(frameworks)basho
    23. 23. Basic Operations // Delete an object db.remove(webinars, node.js) // Does this key exist? db.exists(frameworks, node.js) // Give me them all db.getAll(frameworks) // But filter them too (uses MapReduce) db.getAll(frameworks, { where: { language: "javascript" }})basho
    24. 24. Basic Operations // Delete an object db.remove(webinars, node.js) // Does this key exist? db.exists(frameworks, node.js) // Give me them all db.getAll(frameworks) // But filter them too (uses MapReduce) db.getAll(frameworks, { where: { language: "javascript" }}) // How many are there? db.count(frameworks)basho
    25. 25. Meta Object db.save(‘bucket’, ‘key’, data, META, cb) function cb(err, data, META){ }basho
    26. 26. Meta Object db.save(‘bucket’, ‘key’, data, META, cb)basho
    27. 27. Meta Object db.save(‘bucket’, ‘key’, data, META, cb) • Request-time optionsbasho
    28. 28. Meta Object db.save(‘bucket’, ‘key’, data, META, cb) • Request-time options •contentTypebasho
    29. 29. Meta Object db.save(‘bucket’, ‘key’, data, META, cb) • Request-time options •contentType •clientIdbasho
    30. 30. Meta Object db.save(‘bucket’, ‘key’, data, META, cb) • Request-time options •contentType •clientId • links, usermetabasho
    31. 31. Meta Object db.save(‘bucket’, ‘key’, data, META, cb) • Request-time options •contentType •clientId • links, usermeta • quorums (r,w,dw), returnBodybasho
    32. 32. Meta Object function cb(err, data, META){ }basho
    33. 33. Meta Object function cb(err, data, META){ } • Response-time metadatabasho
    34. 34. Meta Object function cb(err, data, META){ } • Response-time metadata • bucket, key, vclockbasho
    35. 35. Meta Object function cb(err, data, META){ } • Response-time metadata • bucket, key, vclock • links, usermetabasho
    36. 36. Meta Object function cb(err, data, META){ } • Response-time metadata • bucket, key, vclock • links, usermeta • lastMod, etag, statusCodebasho
    37. 37. Using Metabasho
    38. 38. Using Meta // Add a link to the object db.get(frameworks, node.js,   function(err, data, meta){     meta.addLink({bucket:vm, key:v8, tag:vm});     db.save(frameworks, node.js, data, meta)   })basho
    39. 39. Using Meta // Add a link to the object db.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 type db.save(pages, index.html,         <html><body>Hello, world!</body></html>,         {contentType: html})basho
    40. 40. Querying Beyond Key-Valuebasho
    41. 41. Link-walkingbasho
    42. 42. Link-walking // Find friends db.walk(people, sean, [[_,friend]])basho
    43. 43. Link-walking // Find friends db.walk(people, sean, [[_,friend]]) // Find acquaintances of friends db.walk(people, mathias,         [[_,friend],          [people,_]])basho
    44. 44. MapReducebasho
    45. 45. MapReduce // Execute a MapReduce query db.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);        })basho
    46. 46. MapReduce // Execute a MapReduce query db.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 query db.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()basho
    47. 47. MapReducebasho
    48. 48. MapReduce // Initiate MapReduce with a key-filter db.add({ bucket: emails,          key_filters: [["ends_with", "basho.com"]] }) // Map with a phase-argument   .map({ name:Riak.mapByFields,          arg: { joined:2010-01-01 })   .run()basho
    49. 49. Riak Searchbasho
    50. 50. Riak Search // Turn on automatic document indexing db.enableIndex(documents)basho
    51. 51. Riak Search // Turn on automatic document indexing db.enableIndex(documents) // Perform a simple search db.search(documents, title:scalable)basho
    52. 52. Riak Search // Turn on automatic document indexing db.enableIndex(documents) // Perform a simple search db.search(documents, title:scalable) // Start a MapReduce query with search db.addSearch(documents, title:scalable) // From here, add map and reduce phasesbasho
    53. 53. Running Testsbasho
    54. 54. Test Serverbasho
    55. 55. Test Server // Add test server to your tests var TestServer = require(riak-js).TestServerbasho
    56. 56. Test Server // Add test server to your tests var TestServer = require(riak-js).TestServer var testServer = new TestServer({binDir: "/usr/local/bin"})basho
    57. 57. Test Server // Add test server to your tests var TestServer = require(riak-js).TestServer var testServer = new TestServer({binDir: "/usr/local/bin"}) var vows = require(vows), assert = require(assert)basho
    58. 58. Test Server // Add test server to your tests var TestServer = require(riak-js).TestServer var testServer = new TestServer({binDir: "/usr/local/bin"}) var vows = require(vows), assert = require(assert) suite = vows.describe("Example tests")basho
    59. 59. Test Server // Add test server to your tests var TestServer = require(riak-js).TestServer var testServer = new TestServer({binDir: "/usr/local/bin"}) var vows = require(vows), assert = require(assert) suite = vows.describe("Example tests") // Bootstrap the test server suite.addBatch({   setup:{     topic: function(){       var cb = this.callback       testServer.prepare(function(){ testServer.start(cb) })     },basho
    60. 60. Test Server // Add test server to your tests var TestServer = require(riak-js).TestServer var testServer = new TestServer({binDir: "/usr/local/bin"}) var vows = require(vows), assert = require(assert) suite = vows.describe("Example tests") // Bootstrap the test server suite.addBatch({   setup:{     topic: function(){       var cb = this.callback       testServer.prepare(function(){ testServer.start(cb) })     },    works: function(){      assert.isTrue(testServer.started)    } }})basho
    61. 61. Test Serverbasho
    62. 62. Test Server // Clear data before a test suite.addBatch({   stores data:{      topic: function(){        var cb = this.callback        testServer.clear(function(){          db.save(companies, basho, {city:"Cambridge"}, cb)        })      },      successfully: function(err, data, meta){ }   }})basho
    63. 63. Test Server // Clear data before a test suite.addBatch({   stores data:{      topic: function(){        var cb = this.callback        testServer.clear(function(){          db.save(companies, basho, {city:"Cambridge"}, cb)        })      },      successfully: function(err, data, meta){ }   }}) // Shutdown the server at the end suite.addBatch({   teardown:{     topic: function() {       testServer.stop(this.callback)     },     works:function(){       assert.ok(!testServer.started)     }   }})basho
    64. 64. Demo & Code https://github.com/basho/riaktantbasho
    65. 65. Hosted on Joyent http://no.de Demo & Code https://github.com/basho/riaktantbasho
    66. 66. Plug Interested in learning about support, consulting, or Enterprise features? Email info@basho.com or go to http://www.basho.com/ contact.php to talk with us. www.basho.combasho
    67. 67. Plug Interested in learning about support, consulting, or Enterprise features? Email info@basho.com or go to http://www.basho.com/ contact.php to talk with us. www.basho.com mathias@basho.com @roidrage sean@basho.com @seancribbsbasho
    68. 68. Questions?basho
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×