rate

package
v0.0.0-...-1f40b3c Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	RedisClient RedisClient
	Decay       time.Duration
	Limit       int
}

Limiter helper for making sure we don't call something too much

func (Limiter) Count

func (limiter Limiter) Count(key string) (int64, error)

Count returns number of attempts done till now

func (Limiter) Hit

func (limiter Limiter) Hit(key string) (int64, error)

Hit adds a hit to redis and finally returns a new Count

type RedisClient

type RedisClient interface {
	ZAdd(key string, members ...redis.Z) (int64, error)
	ZRemRangeByScore(key, min, max string) (int64, error)
	Expire(key string, expiration time.Duration) (bool, error)
	ZCard(key string) (int64, error)
}

RedisClient interface need to satisfy for Limiter to work

Jump to

Keyboard shortcuts

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