Upgrade to Pro — share decks privately, control downloads, hide ads and more …

riak-js

 riak-js

History and tour of riak-js, the Node.js client for Riak.

4d9dd9bd8d3d4d0ba8af2acc41d14006?s=128

Mathias Meyer

January 17, 2013
Tweet

Transcript

  1. riak-js Mathias Meyer, @roidrage, Riak Meetup NYC

  2. travis-ci.org

  3. riakhandbook.com

  4. riak-js

  5. simple node.js library for riak

  6. simple node.js library for riak

  7. heavily used in riak handbook

  8. ancient history

  9. first commit

  10. 2 march 2010

  11. frank06/riak-js

  12. javascript

  13. port to coffeescript

  14. rewritten in javascript

  15. mostlyserious/riak-js

  16. senchalabs/riak-js

  17. mostlyserious/riak-js

  18. apply(roidrage)

  19. october 2011

  20. v0.4.1

  21. api changes

  22. november 2012

  23. v0.9.0

  24. simple interface

  25. riak = require('riak-js').getClient()

  26. riak.get('users', 'roidrage')

  27. user = {name: 'Mathias Meyer'} riak.save('users', 'roidrage', user)

  28. riak.get('users', 'roidrage', function(error, data) { console.log(data); } )

  29. riak.get('users', 'roidrage', function(error, data) { if (error.notFound) { console.log('User doesn't

    exist!'); } } )
  30. meta

  31. riak.get('users', 'roidrage', {r: 1});

  32. riak.get('users', 'roidrage', function(error, data, meta) { console.log(meta.vclock); } )

  33. reusable

  34. riak.get('users', 'roidrage', function(error, user, meta) { user.city = 'Berlin'; riak.save('users',

    'roidrage', user, meta); } )
  35. links

  36. riak.save('users', 'roidrage', user, {links: [{bucket: 'users', key: 'tsantero', tag: 'bromance'}]

    });
  37. riak.walk('users', 'roidrage', [['users', '_', 'bromance']])

  38. map reduce

  39. riak.mapreduce.add('users'). map('Riak.mapValuesJson'). run()

  40. riak.mapreduce.add('users'). map(function(obj) { return [obj.values[0]]; }). run()

  41. javascript!

  42. riak.mapreduce.add('users'). map(function(v) { return [v.values[0].name]; }). reduce('Riak.reduceSort'). run()

  43. search

  44. riak.saveBucket('users', {search: true})

  45. riak.save('users', 'roidrage', {name: 'Mathias Meyer'});

  46. riak.search.find('users', 'name:Mathias*')

  47. search — map reduce

  48. riak.mapreduce.search('users', 'name:Mathias*'). map('Riak.mapValuesJson'). run()

  49. secondary indexes

  50. riak.save('users', 'roidrage', {name: 'Mathias Meyer'}, {index: {name: 'Mathias Meyer', born:

    1977}});
  51. riak.query('users', {born: 1977})

  52. riak.query('users', {born: [1977, 1980]})

  53. instrumentation

  54. riak.registerListener({ 'riak.request.end': function(event) {}, 'riak.request.start': function(event) {} });

  55. metrics

  56. riak.registerListener({ 'riak.request.end': function(event) { var duration = event.finished_at - event.started_at,

    name = 'riak.request.' + event.method.toLowerCase(); metrics.timing(name, runtime); } });
  57. related: http://www.paperplanes.de/2012/12/27/a-plea-for-client-library-instrumentation.html

  58. the future

  59. protocol buffers

  60. custom agents

  61. reconciling conflicts

  62. riak.get('users', 'roidrage', function(error, data, meta) { if (meta.status == 300)

    { // merge siblings } } )
  63. riak.onConflict(function(siblings) { return siblings.reduce(...); })

  64. riak cs

  65. yokozuna