11'use strict' ;
22
3- function _interopDefault ( ex ) { return ( ex && ( typeof ex === 'object' ) && 'default' in ex ) ? ex [ 'default' ] : ex ; }
3+ var Redis = require ( 'redis' ) ;
44
5- var Redis = _interopDefault ( require ( 'redis' ) ) ;
5+ function _interopDefaultLegacy ( e ) { return e && typeof e === 'object' && 'default' in e ? e : { 'default' : e } ; }
6+
7+ var Redis__default = /*#__PURE__*/ _interopDefaultLegacy ( Redis ) ;
68
79var redisStore = function redisStore ( ) {
8- var redisCache = Redis . createClient . apply ( Redis , arguments ) ;
10+ var redisCache = Redis__default [ "default" ] . createClient . apply ( Redis__default [ "default" ] , arguments ) ;
911 var storeArgs = redisCache . options ;
1012 return {
1113 name : 'redis' ,
@@ -19,22 +21,17 @@ var redisStore = function redisStore() {
1921 cb = options ;
2022 options = { } ;
2123 }
22-
2324 options = options || { } ;
24-
2525 if ( ! cb ) {
2626 cb = function cb ( err , result ) {
2727 return err ? reject ( err ) : resolve ( result ) ;
2828 } ;
2929 }
30-
3130 if ( ! self . isCacheableValue ( value ) ) {
3231 return cb ( new Error ( "\"" . concat ( value , "\" is not a cacheable value" ) ) ) ;
3332 }
34-
3533 var ttl = options . ttl || options . ttl === 0 ? options . ttl : storeArgs . ttl ;
3634 var val = JSON . stringify ( value ) || '"undefined"' ;
37-
3835 if ( ttl ) {
3936 redisCache . setex ( key , ttl , val , handleResponse ( cb ) ) ;
4037 } else {
@@ -46,56 +43,45 @@ var redisStore = function redisStore() {
4643 for ( var _len = arguments . length , args = new Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
4744 args [ _key ] = arguments [ _key ] ;
4845 }
49-
5046 var self = this ;
5147 return new Promise ( function ( resolve , reject ) {
5248 var cb ;
5349 var options = { } ;
54-
5550 if ( typeof args [ args . length - 1 ] === 'function' ) {
5651 cb = args . pop ( ) ;
5752 }
58-
5953 if ( args [ args . length - 1 ] instanceof Object && args [ args . length - 1 ] . constructor === Object ) {
6054 options = args . pop ( ) ;
6155 }
62-
6356 if ( ! cb ) {
6457 cb = function cb ( err , result ) {
6558 return err ? reject ( err ) : resolve ( result ) ;
6659 } ;
6760 }
68-
6961 var ttl = options . ttl || options . ttl === 0 ? options . ttl : storeArgs . ttl ;
7062 var multi ;
71-
7263 if ( ttl ) {
7364 multi = redisCache . multi ( ) ;
7465 }
75-
7666 var key ;
7767 var value ;
7868 var parsed = [ ] ;
79-
8069 for ( var i = 0 ; i < args . length ; i += 2 ) {
8170 key = args [ i ] ;
8271 value = args [ i + 1 ] ;
72+
8373 /**
8474 * Make sure the value is cacheable
8575 */
86-
8776 if ( ! self . isCacheableValue ( value ) ) {
8877 return cb ( new Error ( "\"" . concat ( value , "\" is not a cacheable value" ) ) ) ;
8978 }
90-
9179 value = JSON . stringify ( value ) || '"undefined"' ;
9280 parsed . push . apply ( parsed , [ key , value ] ) ;
93-
9481 if ( ttl ) {
9582 multi . setex ( key , ttl , value ) ;
9683 }
9784 }
98-
9985 if ( ttl ) {
10086 multi . exec ( handleResponse ( cb ) ) ;
10187 } else {
@@ -108,13 +94,11 @@ var redisStore = function redisStore() {
10894 if ( typeof options === 'function' ) {
10995 cb = options ;
11096 }
111-
11297 if ( ! cb ) {
11398 cb = function cb ( err , result ) {
11499 return err ? reject ( err ) : resolve ( result ) ;
115100 } ;
116101 }
117-
118102 redisCache . get ( key , handleResponse ( cb , {
119103 parse : true
120104 } ) ) ;
@@ -124,25 +108,19 @@ var redisStore = function redisStore() {
124108 for ( var _len2 = arguments . length , args = new Array ( _len2 ) , _key2 = 0 ; _key2 < _len2 ; _key2 ++ ) {
125109 args [ _key2 ] = arguments [ _key2 ] ;
126110 }
127-
128111 return new Promise ( function ( resolve , reject ) {
129112 var cb ;
130- var options = { } ;
131-
132113 if ( typeof args [ args . length - 1 ] === 'function' ) {
133114 cb = args . pop ( ) ;
134115 }
135-
136116 if ( args [ args . length - 1 ] instanceof Object && args [ args . length - 1 ] . constructor === Object ) {
137- options = args . pop ( ) ;
117+ args . pop ( ) ;
138118 }
139-
140119 if ( ! cb ) {
141120 cb = function cb ( err , result ) {
142121 return err ? reject ( err ) : resolve ( result ) ;
143122 } ;
144123 }
145-
146124 redisCache . mget . apply ( redisCache , [ ] . concat ( args , [ handleResponse ( cb , {
147125 parse : true
148126 } ) ] ) ) ;
@@ -152,25 +130,19 @@ var redisStore = function redisStore() {
152130 for ( var _len3 = arguments . length , args = new Array ( _len3 ) , _key3 = 0 ; _key3 < _len3 ; _key3 ++ ) {
153131 args [ _key3 ] = arguments [ _key3 ] ;
154132 }
155-
156133 return new Promise ( function ( resolve , reject ) {
157134 var cb ;
158- var options = { } ;
159-
160135 if ( typeof args [ args . length - 1 ] === 'function' ) {
161136 cb = args . pop ( ) ;
162137 }
163-
164138 if ( args [ args . length - 1 ] instanceof Object && args [ args . length - 1 ] . constructor === Object ) {
165- options = args . pop ( ) ;
139+ args . pop ( ) ;
166140 }
167-
168141 if ( ! cb ) {
169142 cb = function cb ( err , result ) {
170143 return err ? reject ( err ) : resolve ( result ) ;
171144 } ;
172145 }
173-
174146 redisCache . del . apply ( redisCache , [ ] . concat ( args , [ handleResponse ( cb ) ] ) ) ;
175147 } ) ;
176148 } ,
@@ -181,7 +153,6 @@ var redisStore = function redisStore() {
181153 return err ? reject ( err ) : resolve ( result ) ;
182154 } ;
183155 }
184-
185156 redisCache . flushdb ( handleResponse ( cb ) ) ;
186157 } ) ;
187158 } ,
@@ -193,13 +164,11 @@ var redisStore = function redisStore() {
193164 cb = pattern ;
194165 pattern = '*' ;
195166 }
196-
197167 if ( ! cb ) {
198168 cb = function cb ( err , result ) {
199169 return err ? reject ( err ) : resolve ( result ) ;
200170 } ;
201171 }
202-
203172 redisCache . keys ( pattern , handleResponse ( cb ) ) ;
204173 } ) ;
205174 } ,
@@ -210,7 +179,6 @@ var redisStore = function redisStore() {
210179 return err ? reject ( err ) : resolve ( result ) ;
211180 } ;
212181 }
213-
214182 redisCache . ttl ( key , handleResponse ( cb ) ) ;
215183 } ) ;
216184 } ,
@@ -219,37 +187,30 @@ var redisStore = function redisStore() {
219187 }
220188 } ;
221189} ;
222-
223190function handleResponse ( cb ) {
224191 var opts = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
225192 return function ( err , result ) {
226193 if ( err ) {
227194 return cb && cb ( err ) ;
228195 }
229-
230196 if ( opts . parse ) {
231197 var isMultiple = Array . isArray ( result ) ;
232-
233198 if ( ! isMultiple ) {
234199 result = [ result ] ;
235200 }
236-
237201 result = result . map ( function ( _result ) {
238202 try {
239203 _result = JSON . parse ( _result ) ;
240204 } catch ( e ) {
241205 return cb && cb ( e ) ;
242206 }
243-
244207 return _result ;
245208 } ) ;
246209 result = isMultiple ? result : result [ 0 ] ;
247210 }
248-
249211 return cb && cb ( null , result ) ;
250212 } ;
251213}
252-
253214var methods = {
254215 create : function create ( ) {
255216 return redisStore . apply ( void 0 , arguments ) ;
0 commit comments