Skip to content

Commit

Permalink
Use increments in Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsnaps committed Apr 2, 2024
1 parent 67f74d4 commit 1329e72
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 2 additions & 4 deletions limitador-server/examples/limits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
-
namespace: test_namespace
max_value: 10
seconds: 60
seconds: 10
conditions:
- "req.method == 'GET'"
variables:
- user_id
-
namespace: test_namespace
max_value: 5
seconds: 60
seconds: 10
conditions:
- "req.method == 'POST'"
variables:
- user_id
2 changes: 1 addition & 1 deletion limitador/src/storage/redis/counters_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ mod tests {
}

#[test]
fn insert_saves_0_when_redis_val_is_none() {
fn insert_saves_zero_when_redis_val_is_none() {
let max_val = 10;
let mut values = HashMap::new();
values.insert("app_id".to_string(), "1".to_string());
Expand Down
4 changes: 3 additions & 1 deletion limitador/src/storage/redis/redis_cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ impl AsyncCounterStorage for CachedRedisStorage {
counter_ttls_msecs[i],
ttl_margin,
);
let remaining = counter.max_value() - counter_vals[i].unwrap_or(0) - delta;
let remaining = counter.max_value()
- counter_vals[i].unwrap_or(0)
- delta;
if first_limited.is_none() && remaining < 0 {
first_limited = Some(Authorization::Limited(
counter.limit().name().map(|n| n.to_owned()),
Expand Down

0 comments on commit 1329e72

Please sign in to comment.