redisqm

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package redisqm defines a Redis-based quota.Manager implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager implements the quota.Manager interface backed by a Redis-based token bucket implementation.

func New

func New(client RedisClient, opts ManagerOptions) *Manager

New returns a new Redis-based quota.Manager.

func (*Manager) GetTokens

func (m *Manager) GetTokens(ctx context.Context, numTokens int, specs []quota.Spec) error

GetTokens implements the quota.Manager API.

func (*Manager) Load

func (m *Manager) Load(ctx context.Context) error

Load attempts to load Redis scripts used by the Manager into the Redis cluster.

A Manager will operate successfully if this method is not called or fails, but a successful Load will reduce bandwidth to/from the Redis cluster substantially.

func (*Manager) PutTokens

func (m *Manager) PutTokens(ctx context.Context, numTokens int, specs []quota.Spec) error

PutTokens implements the quota.Manager API.

func (*Manager) ResetQuota

func (m *Manager) ResetQuota(ctx context.Context, specs []quota.Spec) error

ResetQuota implements the quota.Manager API.

This function will reset every quota and return the first error encountered, if any, but will continue trying to reset every quota even if an error is encountered.

type ManagerOptions

type ManagerOptions struct {
	// Parameters should return the parameters for a given quota.Spec. This
	// value must not be nil.
	Parameters ParameterFunc

	// Prefix is a static prefix to apply to all Redis keys; this is useful
	// if running on a multi-tenant Redis cluster.
	Prefix string
}

ManagerOptions holds the parameters for a Manager.

type ParameterFunc

type ParameterFunc func(spec quota.Spec) (capacity int, rate float64)

ParameterFunc is a function that should return a token bucket's parameters for a given quota specification.

type RedisClient

type RedisClient interface {
	// Everything required by the redistb.RedisClient interface
	redistb.RedisClient
}

RedisClient is an interface that encompasses the various methods used by this quota.Manager, and allows selecting among different Redis client implementations (e.g. regular Redis, Redis Cluster, sharded, etc.)

Jump to

Keyboard shortcuts

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