Bumps [time](https://github.com/time-rs/time) from 0.1.45 to 0.3.30. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/time-rs/time/releases">time's releases</a>.</em></p> <blockquote> <h2>v0.3.30</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.29</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.28</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.27</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.26</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.25</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.24</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.23</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.22</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.21</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.20</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.19</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.18</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.17</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.16</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.15</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <h2>v0.3.14</h2> <p>See the <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">changelog</a> for details.</p> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/time-rs/time/blob/main/CHANGELOG.md">time's changelog</a>.</em></p> <blockquote> <h2>0.3.30 [2023-10-13]</h2> <h3>Added</h3> <ul> <li><code>powerfmt::smart_display::SmartDisplay</code> has been added for the main types in the library. These implementations ensure that values follow the requested fill, width, and alignment when using <code>format!</code> or similar macros. <code>Display</code> is implemented in terms of <code>SmartDisplay</code>.</li> </ul> <h3>Fixed</h3> <ul> <li>Large values no longer wrap around in release mode when using <code>NumericalDuration</code> or <code>NumericalStdDuration</code>.</li> </ul> <h2>0.3.29 [2023-09-24]</h2> <h3>Added</h3> <ul> <li>Niche value optimization for <code>Date</code> has been added. Both <code>Date</code> and <code>Option<Date></code> are four bytes.</li> <li>Unit conversions have been added. It is now possible to write <code>Second::per(Day)</code>, which returns the number of seconds in one day. See the types in the <a href="https://time-rs.github.io/api/time/convert/index.html"><code>time::convert</code> module</a> for more information.</li> </ul> <h3>Changed</h3> <ul> <li>The diagnostic for <code>--cfg unsound_local_offset</code> has been removed.</li> <li><code>#![feature(no_coverage)]</code> was previously used internally for code coverage. It is no longer used, so it has been removed.</li> <li>The default value for <code>modifier::OffsetHour</code> has been changed. This was unintentionally changed in v0.3.17 and went unnoticed until now. The sign is now only present if needed by default, as was the case previously. This does not affect any situation where <code>format_description!</code> or <code>format_description::parse</code> is used.</li> </ul> <h3>Fixed</h3> <ul> <li>Adding or subtracting a <code>std::time::Duration</code> to/from an <code>OffsetDateTime</code> will not result in integer overflow internally. It will still panic if the result is out of range.</li> </ul> <h2>0.3.28 [2023-08-27]</h2> <h3>Added</h3> <ul> <li>More additional constants for the well-known <code>Iso8601</code> format description have been added. This avoids the need to manually configure the format.</li> <li>An <code>[end]</code> component has been added. This is ignored during formatting, but is used to indicate the end of input when parsing. If any input remains after this component, an error is returned. This is useful when using the <code>[first]</code> component, as it avoids the need to reorder variants.</li> </ul> <h3>Changed</h3> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li>See full diff in <a href="https://github.com/time-rs/time/commits/v0.3.30">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/storytold/storyteller-rust/network/alerts). </details> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Brandon Thomas <echelon@gmail.com>
limitation
| CI | |
| Latest Version | |
| Documentation | |
| Crate Downloads | |
| License |
Table of Contents
- About
- Usage
- Examples
- Related Projects and References
- Ideas and Future Work
- CI Status
- Code of Conduct
- Issues
- Contributing
- Release History
- Authors
- License
A rate limiter using a fixed window counter for arbitrary keys, backed by Redis.
About
This library provides a fixed window counter for arbitrary keys backed by a Redis instance. The period length and per-period maximum limit are configurable on setup. The communication with the backend is performing in a non-blocking, asynchronous fashion allowing the library to pair with other async frameworks such as Tokio, Actix, etc.
Note: Currently pre-async/await Futures are used (that is Futures 0.1.x) but that may be upgraded in the near future as the Rust 1.39.0 release is near.
Usage
Add limitation to your Cargo.toml:
[dependencies]
limitation = "0.1.1"
Quick Example
The primary type is the Limiter which uses a builder to construct itself.
Once built, use the count method with a key representing a user, a session,
an interaction, etc. Note that count is a Future and therefore has to be
driving to completion with a runtime. For example, to run one count on a key of
"10.0.0.5":
use limitation::Limiter;
use futures::Future;
// Build a Limiter with a default rate with a local running Redis instance
let limiter = Limiter::build("redis://127.0.0.1/").finish()?;
// The key to count and track
let key = "10.0.0.5";
// Start and run a Tokio runtime to drive the Future to completion
tokio::run(
limiter
// Count returns a Status if the key is under the limit and an `Error::LimitExceeded`
// containing a Status if the limit has been exceeded
.count(key)
// This example deals with both limit exceeded and any Redis connection issues. In this
// case we'll print the error to the standard error stream to show the current limit
// status
.map_err(|err| eprintln!("err: {}", err))
// In this case we are under the limit and can print out the limit status to the
// standard output stream
.and_then(|status| {
println!("ok: {:?}", status);
Ok(())
}),
);
The Limiter Builder
The builder for the Limiter has 2 settings which can be customized to the use
case:
limit: The high water mark for number of requests in the period. The default is5000.period: ADurationfor the period window. The default is 60 minutes.
use limitation::Limiter;
use std::time::Duration;
let limiter = Limiter::build("redis://127.0.0.1/")
.limit(5)
.period(Duration::from_secs(10))
.finish()?;
Examples
A simple example that uses this library can be found in limitation-example.
Related Projects and References
The primary inspiration for the implementation was a blog post called An alternative approach to building a simple API Rate limiter using NodeJS and Redis by Atul R.
Other research and references used for this library:
- https://nordicapis.com/everything-you-need-to-know-about-api-rate-limiting/
- https://hechao.li/2018/06/25/Rate-Limiter-Part1/
- https://www.figma.com/blog/an-alternative-approach-to-rate-limiting/
- https://engagor.github.io/blog/2017/05/02/sliding-window-rate-limiter-redis/
Ideas and Future Work
These are some ideas and potential future work for this project. If you're reading this then maybe you're curious or interesting in helping out? Great! Be sure to check out the Contributing section and dig in!
- Investigate and offer alternative rate-limiting algorithms, notably a Sliding Window solution.
- Add async Redis connection pooling with the
bb8andbb8-rediscrates to reduce connection establishment delays. - Add a
statusmethod onLimiterwhich returns they key'sStatuswithout counting a request. - Add
RedisServersupport in an integration testing suite, similar to the infrastructure in the redis crate.
CI Status
Build (master branch)
| Operating System | Stable Rust | Nightly Rust | MSRV |
|---|---|---|---|
| FreeBSD | |||
| Linux | |||
| macOS | |||
| Windows |
Test (master branch)
| Operating System | Stable Rust | Nightly Rust | MSRV |
|---|---|---|---|
| FreeBSD | |||
| Linux | |||
| macOS | |||
| Windows |
Check (master branch)
| Status | |
|---|---|
| Lint | |
| Format |
Code of Conduct
This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to fnichol@nichol.ca.
Issues
If you have any problems with or questions about this project, please contact us through a GitHub issue.
Contributing
You are invited to contribute to new features, fixes, or updates, large or small; we are always thrilled to receive pull requests, and do our best to process them as fast as we can.
Before you start to code, we recommend discussing your plans through a GitHub issue, especially for more ambitious contributions. This gives other contributors a chance to point you in the right direction, give you feedback on your design, and help you find out if someone else is working on the same thing.
Release History
See the changelog for a full release history.
Authors
Created and maintained by Fletcher Nichol (fnichol@nichol.ca).
License
Licensed under the Mozilla Public License Version 2.0 (LICENSE.txt).
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the MPL-2.0 license, shall be licensed as above, without any additional terms or conditions.