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, Dial: func() (redis.Conn, error) { return redis.Dial("tcp", "127.0.0,1:6379", redis.DialPassword("my-password")) }, }) 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:
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 // Dial is the function to use as the dialer. This is ignored when used with // NewWithPool. Dial func() (redis.Conn, error) }
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.