Documentation ¶
Overview ¶
Package redisqm defines a Redis-based quota.Manager implementation.
Index ¶
- type Manager
- func (m *Manager) GetTokens(ctx context.Context, numTokens int, specs []quota.Spec) error
- func (m *Manager) Load(ctx context.Context) error
- func (m *Manager) PutTokens(ctx context.Context, numTokens int, specs []quota.Spec) error
- func (m *Manager) ResetQuota(ctx context.Context, specs []quota.Spec) error
- type ManagerOptions
- type ParameterFunc
- type RedisClient
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) Load ¶
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) ResetQuota ¶
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 ¶
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.)