Skip to content

Commit 7365e32

Browse files
authored
Merge pull request #1093 from strongloop/docs-for-kvao
Add docs for KVAO
2 parents 5bf18b0 + 6796fac commit 7365e32

File tree

6 files changed

+53
-49
lines changed

6 files changed

+53
-49
lines changed

lib/kvao/expire.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ var assert = require('assert');
44
var utils = require('../utils');
55

66
/**
7-
* Set expiration (TTL) for the given key.
7+
* Set the TTL (time to live) in ms (milliseconds) for a given key. TTL is the
8+
* remaining time before a key-value pair is discarded from the database.
89
*
9-
* @param {String} key
10-
* @param {Number} ttl
11-
* @param {Object} options
12-
* @callback cb
13-
* @param {Error} error
10+
* @param {String} key Key to use when searching the database.
11+
* @param {Number} ttl TTL in ms to set for the key.
12+
* @options {Object} options
13+
* @callback {Function} callback
14+
* @param {Error} err Error object.
15+
* @promise
1416
*
15-
* @header KVAO.get(key, cb)
17+
* @header KVAO.expire(key, ttl, cb)
1618
*/
1719
module.exports = function keyValueExpire(key, ttl, options, callback) {
1820
if (callback == undefined && typeof options === 'function') {
@@ -30,4 +32,3 @@ module.exports = function keyValueExpire(key, ttl, options, callback) {
3032
this.getConnector().expire(this.modelName, key, ttl, options, callback);
3133
return callback.promise;
3234
};
33-

lib/kvao/get.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ var assert = require('assert');
44
var utils = require('../utils');
55

66
/**
7-
* Get the value stored for the given key.
7+
* Return the value associated with a given key.
88
*
9-
* @param {String} key
10-
* @callback cb
11-
* @param {Error} error
12-
* @param {*} value
9+
* @param {String} key Key to use when searching the database.
10+
* @options {Object} options
11+
* @callback {Function} callback
12+
* @param {Error} err Error object.
13+
* @param {*} result Value associated with the given key.
14+
* @promise
1315
*
1416
* @header KVAO.get(key, cb)
1517
*/

lib/kvao/iterate-keys.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ var assert = require('assert');
44
var utils = require('../utils');
55

66
/**
7-
* Asynchronously iterate all keys.
7+
* Asynchronously iterate all keys in the database. Similar to `.keys()` but
8+
* instead allows for iteration over large data sets without having to load
9+
* everything into memory at once.
810
*
911
* @param {Object} filter An optional filter object with the following
10-
* properties:
11-
* - `match` - glob string to use to filter returned keys, e.g. 'userid.*'
12-
* All connectors are required to support `*` and `?`.
13-
* They may also support additional special characters that are specific
14-
* to the backing store.
15-
*
12+
* @param {String} filter.match Glob string to use to filter returned
13+
* keys (i.e. `userid.*`). All connectors are required to support `*` and
14+
* `?`. They may also support additional special characters that are
15+
* specific to the backing database.
1616
* @param {Object} options
17-
*
18-
* @returns {AsyncIterator} An object implementing "next(cb) -> Promise"
19-
* function that can be used to iterate all keys.
17+
* @returns {AsyncIterator} An Object implementing `next(cb) -> Promise`
18+
* function that can be used to iterate all keys.
2019
*
2120
* @header KVAO.iterateKeys(filter)
2221
*/

lib/kvao/keys.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,22 @@ var assert = require('assert');
44
var utils = require('../utils');
55

66
/**
7-
* Get all keys.
7+
* Return all keys in the database.
88
*
9-
* **NOTE**
10-
* Building an in-memory array of all keys may be expensive.
11-
* Consider using `iterateKeys` instead.
9+
* **WARNING**: This method is not suitable for large data sets as all
10+
* key-values pairs are loaded into memory at once. For large data sets,
11+
* use `iterateKeys()` instead.
1212
*
1313
* @param {Object} filter An optional filter object with the following
14-
* properties:
15-
* - `match` - glob string to use to filter returned keys, e.g. 'userid.*'
16-
* All connectors are required to support `*` and `?`.
17-
* They may also support additional special characters that are specific
18-
* to the backing store.
14+
* @param {String} filter.match Glob string used to filter returned
15+
* keys (i.e. `userid.*`). All connectors are required to support `*` and
16+
* `?`, but may also support additional special characters specific to the
17+
* database.
1918
* @param {Object} options
20-
* @callback callback
21-
* @param {Error=} err
22-
* @param {[String]} keys The list of keys.
23-
*
19+
* @callback {Function} callback
2420
* @promise
2521
*
22+
*
2623
* @header KVAO.keys(filter, callback)
2724
*/
2825
module.exports = function keyValueKeys(filter, options, callback) {
@@ -57,4 +54,3 @@ module.exports = function keyValueKeys(filter, options, callback) {
5754

5855
return callback.promise;
5956
};
60-

lib/kvao/set.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ var assert = require('assert');
44
var utils = require('../utils');
55

66
/**
7-
* Set the value for the given key.
7+
* Persist a value and associate it with the given key.
88
*
9-
* @param {String} key
10-
* @param {*} value
11-
* @callback cb
12-
* @param {Error} error
9+
* @param {String} key Key to associate with the given value.
10+
* @param {*} value Value to persist.
11+
* @options {Number|Object} options Optional settings for the key-value
12+
* pair. If a Number is provided, it is set as the TTL (time to live) in ms
13+
* (milliseconds) for the key-value pair.
14+
* @property {Number} ttl TTL for the key-value pair in ms.
15+
* @callback {Function} callback
16+
* @param {Error} err Error object.
17+
* @promise
1318
*
1419
* @header KVAO.set(key, value, cb)
1520
*/
@@ -37,4 +42,3 @@ module.exports = function keyValueSet(key, value, options, callback) {
3742
this.getConnector().set(this.modelName, key, value, options, callback);
3843
return callback.promise;
3944
};
40-

lib/kvao/ttl.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ var assert = require('assert');
44
var utils = require('../utils');
55

66
/**
7-
* Get remaining expiration (TTL) for a given key.
7+
* Return the TTL (time to live) for a given key. TTL is the remaining time
8+
* before a key-value pair is discarded from the database.
89
*
9-
* @param {String} key
10-
* @param {Object} options
11-
* @callback cb
10+
* @param {String} key Key to use when searching the database.
11+
* @options {Object} options
12+
* @callback {Function} callback
1213
* @param {Error} error
13-
* @param {Number} ttl The remaining TTL for the given key. `undefined` if TTL
14-
* was not initially set.
14+
* @param {Number} ttl Expiration time for the key-value pair. `undefined` if
15+
* TTL was not initially set.
16+
* @promise
1517
*
1618
* @header KVAO.ttl(key, cb)
1719
*/

0 commit comments

Comments
 (0)