redis

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package redis provides a Redis-backed ratelimit.Store using atomic Lua scripts, for distributed rate limiting across multiple instances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a Redis-backed Store.

func New

func New(client redis.UniversalClient) *Store

New returns a Store backed by client.

func NewFromAddr

func NewFromAddr(addr string) *Store

NewFromAddr returns a Store backed by a client connecting to addr.

func (*Store) Close

func (s *Store) Close() error

Close implements ratelimit.Store.

func (*Store) GiveBackWindow added in v0.0.6

func (s *Store) GiveBackWindow(ctx context.Context, key string) error

GiveBackWindow implements ratelimit.WindowGiver: return one count to the window, never below zero.

The decrement is its own script rather than a read-and-set so that two replicas giving a count back at the same moment cannot lose one of the two. DECR keeps the TTL, which is what makes a give-back land in the window it was charged in rather than extending it.

func (*Store) IncrWindow

func (s *Store) IncrWindow(ctx context.Context, key string, window time.Duration) (int64, error)

IncrWindow implements ratelimit.Store.

func (*Store) PeekWindow added in v0.0.6

func (s *Store) PeekWindow(ctx context.Context, key string) (int64, bool, error)

PeekWindow implements ratelimit.WindowReader: the window counter as it stands.

A missing key is "no requests counted in this window", which is what the counter's own TTL makes it: IncrWindow sets the expiry on the first increment, so a key that is gone is a window that ended.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping implements ratelimit.Store.

func (*Store) TakeTokens

func (s *Store) TakeTokens(ctx context.Context, key string, rate, burst, n int) (bool, error)

TakeTokens implements ratelimit.Store.

Jump to

Keyboard shortcuts

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