@@ -75,7 +75,7 @@ enforce different levels of service (free or paid):
75
75
authenticated_api :
76
76
strategy : token_bucket
77
77
limit : 5000
78
- rate : { interval: '1 hour ', amount: 5000 }
78
+ rate : { interval: '15 minutes ', amount: 500 }
79
79
80
80
.. note ::
81
81
@@ -106,12 +106,12 @@ the number of requests to the API::
106
106
107
107
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
108
108
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
109
- use Symfony\Component\RateLimiter\LimiterInterface ;
109
+ use Symfony\Component\RateLimiter\Limiter ;
110
110
111
111
class ApiController extends AbstractController
112
112
{
113
113
// the variable name must be: "rate limiter name" + "limiter" suffix
114
- public function index(LimiterInterface $anonymousApiLimiter)
114
+ public function index(Limiter $anonymousApiLimiter)
115
115
{
116
116
// create a limiter based on a unique identifier of the client
117
117
// (e.g. the client's IP address, a username/email, an API key, etc.)
@@ -141,7 +141,7 @@ the number of requests to the API::
141
141
and check the rate limiter once for all requests.
142
142
143
143
In other scenarios you may want instead to wait as long as needed until a new
144
- token is available. In those cases, use the ``reserve() `` and `` wait() `` methods ::
144
+ token is available. In those cases, use the ``wait() `` method ::
145
145
146
146
// src/Controller/LuckyController.php
147
147
// ...
@@ -153,7 +153,10 @@ token is available. In those cases, use the ``reserve()`` and ``wait()`` methods
153
153
$limiter = $authenticatedApiLimiter->create($request->getClientIp());
154
154
155
155
// this blocks the application until the given number of tokens can be consumed
156
- $limiter->consume(1)->wait();
156
+ do {
157
+ $limit = $limiter->consume(1);
158
+ $limit->wait();
159
+ } while (!$limit->isAccepted());
157
160
158
161
// ...
159
162
}
@@ -176,7 +179,7 @@ Symfony application. If you prefer to change that, use the ``lock`` and
176
179
anonymous_api_limiter :
177
180
# ...
178
181
# the value is the name of any cache pool defined in your application
179
- storage : ' app.redis_cache'
182
+ cache_pool : ' app.redis_cache'
180
183
# or define a service implementing StorageInterface to use a different
181
184
# mechanism to store the limiter information
182
185
storage : ' App\RateLimiter\CustomRedisStorage'
0 commit comments