File tree 1 file changed +22
-8
lines changed 1 file changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,27 @@ class RedisStore implements Store {
103
103
this . windowMs = options . windowMs ;
104
104
}
105
105
106
+ async runCommandWithRetry ( key : string ) {
107
+ const evalCommand = async ( ) =>
108
+ this . sendCommand (
109
+ "EVALSHA" ,
110
+ await this . loadedScriptSha1 ,
111
+ "1" ,
112
+ this . prefixKey ( key ) ,
113
+ this . resetExpiryOnChange ? "1" : "0" ,
114
+ this . windowMs . toString ( )
115
+ ) ;
116
+
117
+ try {
118
+ const result = await evalCommand ( ) ;
119
+ return result ;
120
+ } catch {
121
+ // TODO: distinguish different error types
122
+ this . loadedScriptSha1 = this . loadScript ( ) ;
123
+ return evalCommand ( ) ;
124
+ }
125
+ }
126
+
106
127
/**
107
128
* Method to increment a client's hit counter.
108
129
*
@@ -111,14 +132,7 @@ class RedisStore implements Store {
111
132
* @returns {IncrementResponse } - The number of hits and reset time for that client
112
133
*/
113
134
async increment ( key : string ) : Promise < IncrementResponse > {
114
- const results = await this . sendCommand (
115
- "EVALSHA" ,
116
- await this . loadedScriptSha1 ,
117
- "1" ,
118
- this . prefixKey ( key ) ,
119
- this . resetExpiryOnChange ? "1" : "0" ,
120
- this . windowMs . toString ( )
121
- ) ;
135
+ const results = await this . runCommandWithRetry ( key ) ;
122
136
123
137
if ( ! Array . isArray ( results ) ) {
124
138
throw new TypeError ( "Expected result to be array of values" ) ;
You can’t perform that action at this time.
0 commit comments