Skip to content

Commit cd40e8b

Browse files
committed
More fixes
1 parent 1eb70c0 commit cd40e8b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

rate_limiter.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ enforce different levels of service (free or paid):
7575
authenticated_api:
7676
strategy: token_bucket
7777
limit: 5000
78-
rate: { interval: '1 hour', amount: 5000 }
78+
rate: { interval: '15 minutes', amount: 500 }
7979
8080
.. note::
8181

@@ -106,12 +106,12 @@ the number of requests to the API::
106106

107107
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
108108
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
109-
use Symfony\Component\RateLimiter\LimiterInterface;
109+
use Symfony\Component\RateLimiter\Limiter;
110110

111111
class ApiController extends AbstractController
112112
{
113113
// the variable name must be: "rate limiter name" + "limiter" suffix
114-
public function index(LimiterInterface $anonymousApiLimiter)
114+
public function index(Limiter $anonymousApiLimiter)
115115
{
116116
// create a limiter based on a unique identifier of the client
117117
// (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::
141141
and check the rate limiter once for all requests.
142142

143143
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::
145145

146146
// src/Controller/LuckyController.php
147147
// ...
@@ -153,7 +153,10 @@ token is available. In those cases, use the ``reserve()`` and ``wait()`` methods
153153
$limiter = $authenticatedApiLimiter->create($request->getClientIp());
154154

155155
// 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());
157160

158161
// ...
159162
}
@@ -176,7 +179,7 @@ Symfony application. If you prefer to change that, use the ``lock`` and
176179
anonymous_api_limiter:
177180
# ...
178181
# the value is the name of any cache pool defined in your application
179-
storage: 'app.redis_cache'
182+
cache_pool: 'app.redis_cache'
180183
# or define a service implementing StorageInterface to use a different
181184
# mechanism to store the limiter information
182185
storage: 'App\RateLimiter\CustomRedisStorage'

0 commit comments

Comments
 (0)