Redis smooth throttling
This might be an edge case and not even complicated, but I thought I'd share it. So, I had this use case recently where I needed to throttle email send out speed, while allowing to control it on admin panel. However, the difference from the usual case was that you don't enter for example how many emails to allow per minute or second, but you enter over how long the hole process should be done. So, for example, send all ~1k emails over 1 hour. Luckily, laravel has redis throttling built in. We can utilize it like so: <?php Redis :: throttle ( 'key' ) -> allow ( 1000 ) -> every ( 3600 ) // 1 hour -> then ( function () { /* send */ }, function () { /* release */ }); But, here lies the problem. In this case it will send all that 1000 emails as fast as possible. It might take only a couple of minutes. If you have more than 1k emails, the queue will wait for the remaining time, do nothing, and then after 1 hour will send a bunch of