package redisqm

import "github.com/google/trillian/quota/redis/redisqm"

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

Index

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

Source Files

manager.go

Version
v1.7.1 (latest)
Published
Jan 9, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
5 days ago

Tools for package owners.