Skip to content

Commit

Permalink
add close method to store
Browse files Browse the repository at this point in the history
  • Loading branch information
taoyuan committed Aug 27, 2013
1 parent e1e8fbc commit 9aced6a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/adapters/redis.js
Expand Up @@ -155,4 +155,9 @@ Redis.prototype.clear = function (pattern, callback) {
});
};

Redis.prototype.close = function (cb) {
this.client.quit();
if (cb) process.nextTick(cb);
};


11 changes: 11 additions & 0 deletions lib/store.js
Expand Up @@ -75,4 +75,15 @@ Store.prototype.bucket = function (namespace) {
this.buckets[namespace] = c;
}
return c;
};

/**
* Close store connection
*/
Store.prototype.close = function close(cb) {
if (typeof this.adapter.close === 'function') {
this.adapter.close(cb);
} else if (cb) {
cb();
}
};
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "kvs",
"version": "0.0.1-3",
"version": "0.0.1-4",
"description": "Simple key-value store facade for node.",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions test/common-bucket.js
Expand Up @@ -30,18 +30,22 @@ module.exports = function (getStore) {
function testKvs(name, genValue, options) {

context('bucket ' + name, function () {
var store;
var bucket;
var key;
var value;

beforeEach(function () {
bucket = getStore().crateBucket(support.random.string(), options);
store = getStore();
bucket = store.crateBucket(support.random.string(), options);
key = support.random.string(20);
value = genValue();
});

afterEach(function (done) {
bucket.clear(done);
bucket.clear(function () {
store.close(done);
});
});

describe('get() and set()', function () {
Expand Down

0 comments on commit 9aced6a

Please sign in to comment.