Documentation
¶
Overview ¶
Package slidinglog implements the Sliding Window Log rate limiting algorithm.
It maintains a log of request timestamps within the active sliding time window. This provides 100% exact request counting precision.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Strategy ¶
type Strategy struct{}
Strategy implements the algorithm.Algorithm interface for Sliding Window Log.
func New ¶
func New() *Strategy
New creates a new instance of the Sliding Window Log algorithm strategy.
func (*Strategy) EvaluateMemory ¶
func (s *Strategy) EvaluateMemory(now time.Time, state *algorithm.State, limit int64, window time.Duration) algorithm.Result
EvaluateMemory evaluates the sliding log rate limit state in local RAM. It trims expired timestamps and re-allocates memory when slice capacity waste exceeds 50%.
func (*Strategy) RedisScript ¶
RedisScript returns the atomic Redis Lua script utilizing Redis Sorted Sets (ZSET) with atomic sequence incrementing to guarantee unique member elements under high concurrency.