Guides

Troubleshooting

Common setup and runtime issues across local, Redis, and hybrid providers.
Live key cards remain active while faded stale cards are selected by a periodic cleanup sweep.
Lazy expiry keeps reads current; the optional background loop removes inactive state over time.

Redis-backed code does not compile

Enable exactly one runtime feature: redis-tokio or redis-smol. RateLimiterBuilder::redis, RateLimiterBuilder::hybrid, and the Redis and hybrid types need one of them. Local provider needs neither.

Redis operations fail

Verify Redis 7.2+, connection URL, connection manager, and consistent prefixes.

Old v1 examples fail

v2 removed RateLimiter, RateLimiterOptions, provider option structs, and numeric configuration setters. Construct LocalRateLimiterProvider, RedisRateLimiterProvider, or HybridRateLimiterProvider directly and use semantic configuration types. See Configuration Types for the v2 replacements and defaults.

Old v2 examples fail

In 3.0, RateLimiterBuilder is a struct, not a trait. LocalRateLimiterBuilder, RedisRateLimiterBuilder, and HybridRateLimiterBuilder do not exist. A use trypema::RateLimiterBuilder; line that only brought the trait methods into scope is now an unused import. See Migrating from 2.x to 3.0.

Limits differ across instances

  • Local state is process-scoped.
  • Redis-backed instances must share namespace and settings.
  • Hybrid increments reach Redis within SyncInterval. Hybrid read-only calls answer from local state up to AllowedLag old, and from a cached rejection until its retry time ends. Use allowed_lag_applies_to_rejections(true) to bound the absolute rejection cache by AllowedLag.

Redis keys fail validation

RedisKey must be non-empty, at most 255 bytes, and contain no :.

Cleanup does not run

build() starts cleanup unless builder disabled it. Call start_cleanup_loop() after a manual stop; calls are idempotent. Hybrid synchronization is not stopped by disabling cleanup.

Redis reports too many results to unpack

Trypema 2.2.0 and earlier versions can get this error from Redis. It has two causes:

  • Many keys become stale together: approximately 1,600 keys of the absolute strategy, or 1,143 keys of the suppressed strategy. Then cleanup and the Redis clear() fail on each pass, and the stale keys stay in Redis.
  • One key has 8,000 or more expired buckets. Then inc, get, delete, and the conditional sets fail for that key. This occurs only with a small bucket size, such as 1 ms.

To correct this, upgrade to 2.2.1 or a later version. No manual Redis step is necessary. See Cleanup.