Skip to content

feat: ratelimit Redis store adapter #214

@FumingPower3925

Description

@FumingPower3925

Summary

Add a Redis-backed ratelimit.Store implementation for distributed rate limiting.

Context

The ratelimit middleware defines:

type Store interface {
    Allow(key string) (allowed bool, remaining int, resetAt time.Time, err error)
}

Currently uses a sharded in-memory token bucket. For multi-instance deployments, rate limits must be shared via Redis.

Scope

  • Implement RedisStore satisfying ratelimit.Store (and optionally StoreUndo)
  • Use Lua script for atomic check-and-decrement (EVALSHA)
  • Sliding window or token bucket algorithm in Redis
  • Key prefix configurable (default: rl:)
  • TTL auto-set from the rate window
  • Use celeris's native Redis driver

Design Principle

The adapter depends on the existing Store interface — no changes to the ratelimit middleware itself.

Metadata

Metadata

Labels

middlewareMiddleware implementation

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions