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.

Mathias Meyer

January 17, 2013
Tweet

More Decks by Mathias Meyer

Other Decks in Programming

Transcript

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

    View full-size slide

  2. travis-ci.org

    View full-size slide

  3. riakhandbook.com

    View full-size slide

  4. simple node.js
    library for riak

    View full-size slide

  5. simple node.js
    library for riak

    View full-size slide

  6. heavily used in
    riak handbook

    View full-size slide

  7. ancient history

    View full-size slide

  8. first commit

    View full-size slide

  9. 2 march 2010

    View full-size slide

  10. frank06/riak-js

    View full-size slide

  11. port to coffeescript

    View full-size slide

  12. rewritten in javascript

    View full-size slide

  13. mostlyserious/riak-js

    View full-size slide

  14. senchalabs/riak-js

    View full-size slide

  15. mostlyserious/riak-js

    View full-size slide

  16. apply(roidrage)

    View full-size slide

  17. october 2011

    View full-size slide

  18. november 2012

    View full-size slide

  19. simple interface

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  24. riak.get('users', 'roidrage',
    function(error, data) {
    if (error.notFound) {
    console.log('User doesn't exist!');
    }
    }
    )

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  29. riak.walk('users', 'roidrage',
    [['users', '_', 'bromance']])

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  36. search — map reduce

    View full-size slide

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

    View full-size slide

  38. secondary indexes

    View full-size slide

  39. riak.save('users', 'roidrage',
    {name: 'Mathias Meyer'},
    {index: {name: 'Mathias Meyer',
    born: 1977}});

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  42. instrumentation

    View full-size slide

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

    View full-size slide

  44. 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);
    }
    });

    View full-size slide

  45. related:
    http://www.paperplanes.de/2012/12/27/a-plea-for-client-library-instrumentation.html

    View full-size slide

  46. protocol buffers

    View full-size slide

  47. custom agents

    View full-size slide

  48. reconciling conflicts

    View full-size slide

  49. riak.get('users', 'roidrage',
    function(error, data, meta) {
    if (meta.status == 300) {
    // merge siblings
    }
    }
    )

    View full-size slide

  50. riak.onConflict(function(siblings) {
    return siblings.reduce(...);
    })

    View full-size slide