File tree Expand file tree Collapse file tree 1 file changed +4
-6
lines changed
Expand file tree Collapse file tree 1 file changed +4
-6
lines changed Original file line number Diff line number Diff line change @@ -182,14 +182,18 @@ public function get($key): mixed
182182 #[Override]
183183 public function increment ($ key , $ value = 1 ): int |float |false
184184 {
185+ $ now = $ this ->getUTCDateTime ();
186+
185187 $ result = $ this ->collection ->findOneAndUpdate (
186188 [
187189 '_id ' => $ this ->prefix . $ key ,
190+ 'expires_at ' => ['$gt ' => $ now ],
188191 ],
189192 [
190193 '$inc ' => ['value ' => $ value ],
191194 ],
192195 [
196+ 'projection ' => ['value ' => 1 , 'expires_at ' => 1 ],
193197 'returnDocument ' => FindOneAndUpdate::RETURN_DOCUMENT_AFTER ,
194198 ],
195199 );
@@ -198,12 +202,6 @@ public function increment($key, $value = 1): int|float|false
198202 return false ;
199203 }
200204
201- if ($ result ['expires_at ' ] <= $ this ->getUTCDateTime ()) {
202- $ this ->forgetIfExpired ($ key );
203-
204- return false ;
205- }
206-
207205 return $ result ['value ' ];
208206 }
209207
You can’t perform that action at this time.
0 commit comments