@@ -5,24 +5,21 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
55var Redis = _interopDefault ( require ( 'redis' ) ) ;
66
77var redisStore = function redisStore ( ) {
8- for ( var _len = arguments . length , args = Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
9- args [ _key ] = arguments [ _key ] ;
10- }
11-
12- var redisCache = Redis . createClient . apply ( Redis , args ) ;
8+ var redisCache = Redis . createClient . apply ( Redis , arguments ) ;
139 var storeArgs = redisCache . options ;
14-
1510 return {
1611 name : 'redis' ,
1712 getClient : function getClient ( ) {
1813 return redisCache ;
1914 } ,
2015 set : function set ( key , value , options , cb ) {
16+ var self = this ;
2117 return new Promise ( function ( resolve , reject ) {
2218 if ( typeof options === 'function' ) {
2319 cb = options ;
2420 options = { } ;
2521 }
22+
2623 options = options || { } ;
2724
2825 if ( ! cb ) {
@@ -31,6 +28,10 @@ var redisStore = function redisStore() {
3128 } ;
3229 }
3330
31+ if ( ! self . isCacheableValue ( value ) ) {
32+ return cb ( new Error ( "\"" . concat ( value , "\" is not a cacheable value" ) ) ) ;
33+ }
34+
3435 var ttl = options . ttl || options . ttl === 0 ? options . ttl : storeArgs . ttl ;
3536 var val = JSON . stringify ( value ) || '"undefined"' ;
3637
@@ -42,14 +43,13 @@ var redisStore = function redisStore() {
4243 } ) ;
4344 } ,
4445 mset : function mset ( ) {
45- for ( var _len2 = arguments . length , args = Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) {
46- args [ _key2 ] = arguments [ _key2 ] ;
46+ for ( var _len = arguments . length , args = new Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
47+ args [ _key ] = arguments [ _key ] ;
4748 }
4849
49- var _this = this ;
50-
50+ var self = this ;
5151 return new Promise ( function ( resolve , reject ) {
52- var cb = void 0 ;
52+ var cb ;
5353 var options = { } ;
5454
5555 if ( typeof args [ args . length - 1 ] === 'function' ) {
@@ -67,24 +67,25 @@ var redisStore = function redisStore() {
6767 }
6868
6969 var ttl = options . ttl || options . ttl === 0 ? options . ttl : storeArgs . ttl ;
70+ var multi ;
7071
71- var multi = void 0 ;
7272 if ( ttl ) {
7373 multi = redisCache . multi ( ) ;
7474 }
7575
76- var key = void 0 ;
77- var value = void 0 ;
76+ var key ;
77+ var value ;
7878 var parsed = [ ] ;
79+
7980 for ( var i = 0 ; i < args . length ; i += 2 ) {
8081 key = args [ i ] ;
8182 value = args [ i + 1 ] ;
82-
8383 /**
8484 * Make sure the value is cacheable
8585 */
86- if ( ! _this . isCacheableValue ( value ) ) {
87- return cb ( new Error ( 'value cannot be ' + value ) ) ;
86+
87+ if ( ! self . isCacheableValue ( value ) ) {
88+ return cb ( new Error ( "\"" . concat ( value , "\" is not a cacheable value" ) ) ) ;
8889 }
8990
9091 value = JSON . stringify ( value ) || '"undefined"' ;
@@ -114,16 +115,18 @@ var redisStore = function redisStore() {
114115 } ;
115116 }
116117
117- redisCache . get ( key , handleResponse ( cb , { parse : true } ) ) ;
118+ redisCache . get ( key , handleResponse ( cb , {
119+ parse : true
120+ } ) ) ;
118121 } ) ;
119122 } ,
120123 mget : function mget ( ) {
121- for ( var _len3 = arguments . length , args = Array ( _len3 ) , _key3 = 0 ; _key3 < _len3 ; _key3 ++ ) {
122- args [ _key3 ] = arguments [ _key3 ] ;
124+ for ( var _len2 = arguments . length , args = new Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) {
125+ args [ _key2 ] = arguments [ _key2 ] ;
123126 }
124127
125128 return new Promise ( function ( resolve , reject ) {
126- var cb = void 0 ;
129+ var cb ;
127130 var options = { } ;
128131
129132 if ( typeof args [ args . length - 1 ] === 'function' ) {
@@ -140,16 +143,18 @@ var redisStore = function redisStore() {
140143 } ;
141144 }
142145
143- redisCache . mget . apply ( redisCache , [ ] . concat ( args , [ handleResponse ( cb , { parse : true } ) ] ) ) ;
146+ redisCache . mget . apply ( redisCache , [ ] . concat ( args , [ handleResponse ( cb , {
147+ parse : true
148+ } ) ] ) ) ;
144149 } ) ;
145150 } ,
146151 del : function del ( ) {
147- for ( var _len4 = arguments . length , args = Array ( _len4 ) , _key4 = 0 ; _key4 < _len4 ; _key4 ++ ) {
148- args [ _key4 ] = arguments [ _key4 ] ;
152+ for ( var _len3 = arguments . length , args = new Array ( _len3 ) , _key3 = 0 ; _key3 < _len3 ; _key3 ++ ) {
153+ args [ _key3 ] = arguments [ _key3 ] ;
149154 }
150155
151156 return new Promise ( function ( resolve , reject ) {
152- var cb = void 0 ;
157+ var cb ;
153158 var options = { } ;
154159
155160 if ( typeof args [ args . length - 1 ] === 'function' ) {
@@ -182,7 +187,7 @@ var redisStore = function redisStore() {
182187 } ,
183188 keys : function keys ( ) {
184189 var pattern = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : '*' ;
185- var cb = arguments [ 1 ] ;
190+ var cb = arguments . length > 1 ? arguments [ 1 ] : undefined ;
186191 return new Promise ( function ( resolve , reject ) {
187192 if ( typeof pattern === 'function' ) {
188193 cb = pattern ;
@@ -217,14 +222,14 @@ var redisStore = function redisStore() {
217222
218223function handleResponse ( cb ) {
219224 var opts = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
220-
221225 return function ( err , result ) {
222226 if ( err ) {
223227 return cb && cb ( err ) ;
224228 }
225229
226230 if ( opts . parse ) {
227231 var isMultiple = Array . isArray ( result ) ;
232+
228233 if ( ! isMultiple ) {
229234 result = [ result ] ;
230235 }
@@ -235,9 +240,9 @@ function handleResponse(cb) {
235240 } catch ( e ) {
236241 return cb && cb ( e ) ;
237242 }
243+
238244 return _result ;
239245 } ) ;
240-
241246 result = isMultiple ? result : result [ 0 ] ;
242247 }
243248
@@ -247,7 +252,7 @@ function handleResponse(cb) {
247252
248253var methods = {
249254 create : function create ( ) {
250- return redisStore . apply ( undefined , arguments ) ;
255+ return redisStore . apply ( void 0 , arguments ) ;
251256 }
252257} ;
253258
0 commit comments