slidinglog

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 2 Imported by: 0

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) Name

func (s *Strategy) Name() string

Name returns the unique identifier string of the algorithm strategy.

func (*Strategy) RedisScript

func (s *Strategy) RedisScript() string

RedisScript returns the atomic Redis Lua script utilizing Redis Sorted Sets (ZSET) with atomic sequence incrementing to guarantee unique member elements under high concurrency.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL