File tree 2 files changed +16
-1955
lines changed
2 files changed +16
-1955
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,10 @@ async def __aexit__(
84
84
) -> None :
85
85
"""Do nothing. We need this to ``__aenter__`` to work."""
86
86
87
+ async def redis_version (self ):
88
+ version = await self ._backend .info (section = 'SERVER' )
89
+ return version ['redis_version' ]
90
+
87
91
# Private API:
88
92
89
93
async def _acquire (self ) -> None :
@@ -95,7 +99,18 @@ async def _acquire(self) -> None:
95
99
pipeline = self ._backend .pipeline ()
96
100
97
101
async with self ._lock :
98
- current_rate = await self ._run_pipeline (cache_key , pipeline )
102
+ redis_version = await self .redis_version ()
103
+
104
+ if int (redis_version .split ('.' )[0 ]) < 7 :
105
+ current_rate , * _ = await pipeline .incr (cache_key ).execute ()
106
+ if current_rate == 1 :
107
+ await pipeline .execute_command (
108
+ 'EXPIRE' ,
109
+ cache_key ,
110
+ self ._rate_spec .seconds ,
111
+ ).execute ()
112
+ else :
113
+ current_rate = await self ._run_pipeline (cache_key , pipeline )
99
114
# This looks like a coverage error on 3.10:
100
115
if current_rate > self ._rate_spec .requests : # pragma: no cover
101
116
raise RateLimitError ('Rate limit is hit' , current_rate )
You can’t perform that action at this time.
0 commit comments