Documentation ¶
Overview ¶
Package redigostore offers Redis-based store implementation for throttled using redigo.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type RedigoPool ¶ added in v2.8.0
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 https://github.com/mna/redisc.
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 ¶
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.