@@ -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 ) {
@@ -71,7 +71,15 @@ function redisStore(args) {
7171 }
7272
7373 if ( opts . parse ) {
74- result = JSON . parse ( result ) ;
74+
75+ try {
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+ }
80+ } catch ( e ) {
81+ return cb && cb ( e ) ;
82+ }
7583 }
7684
7785 if ( cb ) {
@@ -113,10 +121,12 @@ function redisStore(args) {
113121 * @param {Function } [cb] - A callback that returns a potential error, otherwise null
114122 */
115123 self . set = function ( key , value , options , cb ) {
124+
116125 if ( typeof options === 'function' ) {
117126 cb = options ;
118127 options = { } ;
119128 }
129+
120130 options = options || { } ;
121131
122132 var ttl = ( options . ttl || options . ttl === 0 ) ? options . ttl : redisOptions . ttl ;
@@ -126,7 +136,6 @@ function redisStore(args) {
126136 return cb && cb ( err ) ;
127137 }
128138 var val = JSON . stringify ( value ) ;
129-
130139 if ( ttl ) {
131140 conn . setex ( key , ttl , val , handleResponse ( conn , cb ) ) ;
132141 } else {
0 commit comments