15. Basic Operations
// Get a client
var db = require('riak-js').getClient()
basho
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. 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. 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
20. Basic Operations
// Delete an object
db.remove('webinars', 'node.js')
basho
21. Basic Operations
// Delete an object
db.remove('webinars', 'node.js')
// Does this key exist?
db.exists('frameworks', 'node.js')
basho
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. 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. 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. Meta Object
db.save(‘bucket’, ‘key’, data, META, cb)
function cb(err, data, META){ }
basho
26. Meta Object
db.save(‘bucket’, ‘key’, data, META, cb)
basho
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. 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
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. 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
55. Test Server
// Add test server to your tests
var TestServer = require('riak-js').TestServer
basho
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. 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. 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. 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. 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
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. 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
65. Hosted on Joyent
http://no.de
Demo & Code
https://github.com/basho/riaktant
basho
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.com
basho
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
@seancribbs
basho
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