v2.12.0 Latest Latest

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

Go to latest
Published: Jun 29, 2023 License: BSD-3-Clause Imports: 4 Imported by: 6



Package redigostore offers Redis-based store implementation for throttled using redigo.



This section is empty.


This section is empty.


func NewCtx added in v2.10.0

func NewCtx(pool *redis.Pool, keyPrefix string, db int) (throttled.GCRAStoreCtx, error)

NewCtx is the version of New that can be used with a context-aware ratelimiter.


type RedigoPool added in v2.8.0

type RedigoPool interface {
	Get() redis.Conn

RedigoPool is the interface for retrieving a Redis connection from a Redigo pool. This is satisfied by the normal Redigo redis.Pool, but also works with the Redis cluster connection pool provided by redisc.Cluster as part of

type RedigoStore

type RedigoStore struct {
	// contains filtered or unexported fields

RedigoStore implements a Redis-based store using redigo.

func New

func New(pool RedigoPool, keyPrefix string, db int) (*RedigoStore, error)

New creates a new Redis-based store, using the provided pool to get its connections. The keys will have the specified keyPrefix, which may be an empty string, and the database index specified by db will be selected to store the keys. Any updating operations will reset the key TTL to the provided value rounded down to the nearest second. Depends on Redis 2.6+ for EVAL support.

func (*RedigoStore) CompareAndSwapWithTTL

func (r *RedigoStore) CompareAndSwapWithTTL(key string, old, new int64, ttl time.Duration) (bool, error)

CompareAndSwapWithTTL atomically compares the value at key to the old value. If it matches, it sets it to the new value and returns true. Otherwise, it returns false. If the key does not exist in the store, it returns false with no error. If the swap succeeds, the ttl for the key is updated atomically.

func (*RedigoStore) GetWithTime

func (r *RedigoStore) GetWithTime(key string) (int64, time.Time, error)

GetWithTime returns the value of the key if it is in the store or -1 if it does not exist. It also returns the current time at the redis server to microsecond precision.

func (*RedigoStore) SetIfNotExistsWithTTL

func (r *RedigoStore) SetIfNotExistsWithTTL(key string, value int64, ttl time.Duration) (bool, error)

SetIfNotExistsWithTTL sets the value of key only if it is not already set in the store it returns whether a new value was set. If a new value was set, the ttl in the key is also set, though this operation is not performed atomically.

Jump to

Keyboard shortcuts

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