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 Mar 27, 2024
1 parent 2f5e6cd commit e4e0e34
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions limitador/src/storage/redis/redis_cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl AsyncCounterStorage for CachedRedisStorage {
for counter in counters.iter_mut() {
match cached_counters.get(counter) {
Some(val) => {
if first_limited.is_none() && val - delta < 0 {
if first_limited.is_none() && val + delta >= counter.max_value() {
let a = Authorization::Limited(
counter.limit().name().map(|n| n.to_owned()),
);
Expand All @@ -93,7 +93,7 @@ impl AsyncCounterStorage for CachedRedisStorage {
first_limited = Some(a);
}
if load_counters {
counter.set_remaining(val);
counter.set_remaining(counter.max_value() - val);
// todo: how do we get the ttl for this entry?
// counter.set_expires_in(Duration::from_secs(counter.seconds()));
}
Expand Down Expand Up @@ -138,7 +138,7 @@ impl AsyncCounterStorage for CachedRedisStorage {
counter_ttls_msecs[i],

Check warning on line 138 in limitador/src/storage/redis/redis_cached.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador/src/storage/redis/redis_cached.rs

Check warning on line 138 in limitador/src/storage/redis/redis_cached.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

Diff in /home/runner/work/limitador/limitador/limitador/src/storage/redis/redis_cached.rs
ttl_margin,
);
let remaining = counter_vals[i].unwrap_or(counter.max_value()) - delta;
let remaining = counter.max_value() - counter_vals[i].unwrap_or(counter.max_value()) - 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 e4e0e34

Please sign in to comment.