Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade dependencies
- Loading branch information
Showing
17 changed files
with
557 additions
and
534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# http://editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,59 @@ | ||
var kvs = require('kvs'); | ||
|
||
var redisStore = kvs.store('redis', { db: 1 }); | ||
var redisBucket = redisStore.createBucket({ ttl: 100/*seconds*/ }); | ||
var redisStore = kvs.store('redis', {db: 1}); | ||
var redisBucket = redisStore.createBucket({ttl: 100/*seconds*/}); | ||
|
||
var memoryStore = kvs.store('memory'); | ||
var memoryBucket = memoryStore.createBucket({ max: 100, ttl: 10/*seconds*/ }); | ||
var memoryBucket = memoryStore.createBucket({max: 100, ttl: 10/*seconds*/}); | ||
|
||
|
||
redisBucket.set('foo', 'bar', function(err) { | ||
if (err) { throw err; } | ||
redisBucket.set('foo', 'bar', function (err) { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
redisBucket.get('foo', function(err, result) { | ||
console.log(result); | ||
// >> 'bar' | ||
redisBucket.del('foo', function(err) {}); | ||
redisBucket.get('foo', function (err, result) { | ||
console.log(result); | ||
// >> 'bar' | ||
redisBucket.del('foo', function (err) { | ||
}); | ||
}); | ||
}); | ||
|
||
function getUser(id, cb) { | ||
setTimeout(function () { | ||
console.log("Returning user from slow database."); | ||
cb(null, {id: id, name: 'Bob'}); | ||
}, 100); | ||
setTimeout(function () { | ||
console.log("Returning user from slow database."); | ||
cb(null, {id: id, name: 'Bob'}); | ||
}, 100); | ||
} | ||
|
||
var user_id = 123; | ||
var key = '#' + user_id; // for test if key is not the parameter (user_id) to load. | ||
|
||
// Using namespace "user" | ||
var redisLoadBucket = redisStore.createBucket('user', { | ||
ttl: 100, /*seconds*/ | ||
|
||
// method to load a thing if it's not in the bucket. | ||
load: function (user_id, cb) { | ||
// this method will only be called if it's not already in bucket, and will | ||
// store the result in the bucket store. | ||
getUser(user_id, cb); | ||
} | ||
ttl: 100, /*seconds*/ | ||
|
||
// method to load a thing if it's not in the bucket. | ||
load: function (user_id, cb) { | ||
// this method will only be called if it's not already in bucket, and will | ||
// store the result in the bucket store. | ||
getUser(user_id, cb); | ||
} | ||
}); | ||
|
||
// `user_id` is the parameter used to load. | ||
// if no parameter is specified for loading, the `key` will be used. | ||
redisLoadBucket.get(key, user_id, function (err, user) { | ||
console.log(user); | ||
console.log(user); | ||
|
||
// Second time fetches user from redisLoadBucket | ||
redisLoadBucket.get(key, user_id, function (err, user) { | ||
console.log(user); | ||
}); | ||
// Second time fetches user from redisLoadBucket | ||
redisLoadBucket.get(key, user_id, function (err, user) { | ||
console.log(user); | ||
}); | ||
}); | ||
|
||
// Outputs: | ||
// Returning user from slow database. | ||
// { id: 123, name: 'Bob' } | ||
// { id: 123, name: 'Bob' } | ||
// { id: 123, name: 'Bob' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
var fs = require('fs'); | ||
|
||
exports.store = | ||
exports.Store = require('./lib/store'); | ||
exports.Store = require('./lib/store'); | ||
|
||
exports.__defineGetter__('version', function () { | ||
return JSON.parse(fs.readFileSync(__dirname + '/package.json')).version; | ||
}); | ||
return JSON.parse(fs.readFileSync(__dirname + '/package.json')).version; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.