redis

package
v3.11.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 10 Imported by: 64

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStore

func NewStore(client Client) (limiter.Store, error)

NewStore returns an instance of redis store with defaults.

func NewStoreWithOptions

func NewStoreWithOptions(client Client, options limiter.StoreOptions) (limiter.Store, error)

NewStoreWithOptions returns an instance of redis store with options.

Types

type Client

type Client interface {
	Get(ctx context.Context, key string) *libredis.StringCmd
	Set(ctx context.Context, key string, value interface{}, expiration time.Duration) *libredis.StatusCmd
	Watch(ctx context.Context, handler func(*libredis.Tx) error, keys ...string) error
	Del(ctx context.Context, keys ...string) *libredis.IntCmd
	SetNX(ctx context.Context, key string, value interface{}, expiration time.Duration) *libredis.BoolCmd
	EvalSha(ctx context.Context, sha string, keys []string, args ...interface{}) *libredis.Cmd
	ScriptLoad(ctx context.Context, script string) *libredis.StringCmd
}

Client is an interface thats allows to use a redis cluster or a redis single client seamlessly.

type Store

type Store struct {
	// Prefix used for the key.
	Prefix string
	// MaxRetry is the maximum number of retry under race conditions.
	// Deprecated: this option is no longer required since all operations are atomic now.
	MaxRetry int
	// contains filtered or unexported fields
}

Store is the redis store.

func (*Store) Get

func (store *Store) Get(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error)

Get returns the limit for given identifier.

func (*Store) Increment added in v3.9.0

func (store *Store) Increment(ctx context.Context, key string, count int64, rate limiter.Rate) (limiter.Context, error)

Increment increments the limit by given count & gives back the new limit for given identifier

func (*Store) Peek

func (store *Store) Peek(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error)

Peek returns the limit for given identifier, without modification on current values.

func (*Store) Reset added in v3.3.0

func (store *Store) Reset(ctx context.Context, key string, rate limiter.Rate) (limiter.Context, error)

Reset returns the limit for given identifier which is set to zero.

Jump to

Keyboard shortcuts

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