https://github.com/mcaptcha/cache
Redis module that implements mCaptcha cache and counter
https://github.com/mcaptcha/cache
mcaptcha redis redis-module
Last synced: about 1 year ago
JSON representation
Redis module that implements mCaptcha cache and counter
- Host: GitHub
- URL: https://github.com/mcaptcha/cache
- Owner: mCaptcha
- License: agpl-3.0
- Created: 2021-06-05T14:56:31.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-03-15T11:04:38.000Z (over 2 years ago)
- Last Synced: 2025-03-26T01:02:54.863Z (about 1 year ago)
- Topics: mcaptcha, redis, redis-module
- Language: Rust
- Homepage: https://mcaptcha.org
- Size: 4.47 MB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
mCaptcha Cache
Redis module that implements
leaky bucket algorithm
[](https://github.com/mCaptcha/cache/actions/workflows/linux.yml)
[](https://hub.docker.com/r/mcaptcha/cache)
[](https://deps.rs/repo/github/mCaptcha/cache)
[](http://www.gnu.org/licenses/agpl-3.0)
[](https://matrix.to/#/+mcaptcha:matrix.batsense.net)
## Features
- [x] Timers for individual count
- [x] Clustering
- [x] Persistence through RDB
- [ ] Persistence through AOF
## Motivation
[mCaptcha](https://github.com/mCaptcha/mCaptcha) uses a [leaky-
bucket](https://en.wikipedia.org/wiki/Leaky_bucket)-enabled counter to
keep track of traffic/challenge requests.
- At `t=0`(where `t` is time), if someone is visiting an mCaptcha-protected website, the
counter for that website will be initialized and set to 1.
- It should also automatically decrement(by 1) after a certain period, say
`t=cooldown`. We call this cool down period and is constant for a
website.
- If at `t=x`(where `x
```
## Get counter value
```redis
MCAPTCHA_CACHE.GET
```
## Benchmark
**NOTE:** These benchmarks are for reference only. Do not depend upon
them too much. When in doubt, please craft and run benchmarks that are
better suited to your workload.
To run benchmarks locally, launch Redis server with module loaded and:
```bash
$ make bench
```
- platform: `Intel core i7-9750h`
```bash
➜ cache git:(master) ✗ make bench
./scripts/bench.sh
running set and get without pipelining
SET: 128600.82 requests per second, p50=0.191 msec
GET: 128617.36 requests per second, p50=0.191 msec
mCaptcha cache without piplining
MCAPTCHA_CACHE.ADD_VISITOR mycounter: 127811.86 requests per second, p50=0.207 msec
MCAPTCHA_CACHE.GET mycounter: 123243.77 requests per second, p50=0.199 msec
running set and get with pipelining
SET: 1416430.62 requests per second, p50=0.479 msec
GET: 1644736.88 requests per second, p50=0.391 msec
mCaptcha cache with piplining
MCAPTCHA_CACHE.ADD_VISITOR mycounter: 396039.59 requests per second, p50=1.903 msec
MCAPTCHA_CACHE.GET mycounter: 889679.75 requests per second, p50=0.791 msec
```
## Hacks
I couldn't find any ways to persist timers to disk(`RDB`/`AOF`). So I'm
using a dummy record(`mcaptcha:timer:*` see [Gotchas](#gotchas)) which
will expire after an arbitrary time(see `POCKET_EXPIRY_OFFSET` in
[`lib.rs`](./src/lib.rs)). When that expiry occurs, I derive the key of
the pocket from the values that are passed to expiration event handlers
and perform clean up of both the pocket and counters registered with the
pocket.
Ideally, I should be able to persist timers but I couldn't find ways to
do that.
## Funding
### NLnet
2023 development is funded through the [NGI0 Entrust
Fund](https://nlnet.nl/entrust), via [NLnet](https://nlnet.nl/). Please
see [here](https://nlnet.nl/project/mCaptcha/) for more details.