Skip to content

Commit ce0b29b

Browse files
committed
undefined is allowed to be set if isCacheableValue allows it. Add test.
1 parent 3aeca4a commit ce0b29b

File tree

2 files changed

+123
-88
lines changed

2 files changed

+123
-88
lines changed

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function redisStore(args) {
5757
* Helper to handle callback and release the connection
5858
* @private
5959
* @param {Object} conn - The Redis connection
60-
* @param {Function} [cb] - A callback that returns a potential error and the resoibse
60+
* @param {Function} [cb] - A callback that returns a potential error and the result
6161
* @param {Object} [opts] - The options (optional)
6262
*/
6363
function handleResponse(conn, cb, opts) {
@@ -73,7 +73,10 @@ function redisStore(args) {
7373
if (opts.parse) {
7474

7575
try {
76-
result = JSON.parse(result);
76+
// allow undefined only if allowed by isCacheableValue
77+
if(! ( (result === undefined || result === "undefined") && typeof args.isCacheableValue === 'function' && args.isCacheableValue(result))) {
78+
result = JSON.parse(result);
79+
}
7780
} catch (e) {
7881
return cb && cb(e);
7982
}
@@ -124,10 +127,6 @@ function redisStore(args) {
124127
options = {};
125128
}
126129

127-
if (value === undefined) {
128-
return cb && cb(new Error('value cannot be undefined'));
129-
}
130-
131130
options = options || {};
132131

133132
var ttl = (options.ttl || options.ttl === 0) ? options.ttl : redisOptions.ttl;

0 commit comments

Comments
 (0)