Documentation ¶
Overview ¶
Package redisstore defines a redis-backed storage system for limiting.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New uses a Redis instance to back a rate limiter that to limit the number of permitted events over an interval.
Example ¶
ctx := context.Background() store, err := redisstore.New(&redisstore.Config{ Tokens: 15, Interval: time.Minute, RedisOptions: &redis.Options{ Addr: "127.0.0.1:6379", }, }) if err != nil { log.Fatal(err) } defer store.Close(ctx) limit, remaining, reset, ok, err := store.Take(ctx, "my-key") if err != nil { log.Fatal(err) } _, _, _, _ = limit, remaining, reset, ok
Output:
func NewWithClient ¶
NewWithClient creates a new limiter using the given redis pool. Use this to customize lower-level details about the pool.
Types ¶
type Config ¶
type Config struct { // Tokens is the number of tokens to allow per interval. The default value is // 1. Tokens uint64 // Interval is the time interval upon which to enforce rate limiting. The // default value is 1 second. Interval time.Duration // Redis client options RedisOptions *redis.Options }
Config is used as input to New. It defines the behavior of the storage system.
Click to show internal directories.
Click to hide internal directories.