cache

package
v0.0.0-...-0eef1dd Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCodeRepeated = errors.New("code repeated")
)

Functions

This section is empty.

Types

type RedisCodeCache

type RedisCodeCache struct {
	// contains filtered or unexported fields
}

RedisCodeCache implements VerifyCodeCache with redis cache

func NewRedisCodeCache

func NewRedisCodeCache(cache *redis.Client) *RedisCodeCache

func (*RedisCodeCache) Del

func (r *RedisCodeCache) Del(ctx context.Context, usage auth.Usage, code string) error

func (*RedisCodeCache) Get

func (r *RedisCodeCache) Get(ctx context.Context, usage auth.Usage, code string) (string, error)

func (*RedisCodeCache) Set

func (r *RedisCodeCache) Set(ctx context.Context, usage auth.Usage, code, to string, ttl, retry time.Duration) (bool, error)

type RedisTokenCache

type RedisTokenCache struct {
	// contains filtered or unexported fields
}

RedisTokenCache implements TokenCache interface for redis storage

func NewRedisTokenCache

func NewRedisTokenCache(prefix string, client *redis.Client) *RedisTokenCache

func (*RedisTokenCache) Del

func (r *RedisTokenCache) Del(ctx context.Context, tokenId string) error

func (*RedisTokenCache) Get

func (r *RedisTokenCache) Get(ctx context.Context, tokenId string) (string, error)

func (*RedisTokenCache) Set

func (r *RedisTokenCache) Set(ctx context.Context, tokenId, value string, expire time.Duration) error

func (*RedisTokenCache) TTL

func (r *RedisTokenCache) TTL(ctx context.Context, tokenId string) (time.Duration, error)

type TokenCache

type TokenCache interface {
	// Get returns the given tokenId from the cache, just verifying if it exists
	Get(ctx context.Context, tokenId string) (string, error)
	// TTL returns the rest life-time of the given token
	TTL(ctx context.Context, tokenId string) (time.Duration, error)
	// Del removes the specified tokenId from the cache
	Del(ctx context.Context, tokenId string) error
	// Set sets the specified tokenId to the cache
	Set(ctx context.Context, tokenId, value string, expire time.Duration) error
}

TokenCache stores the token in the cache, and maintains them.

type VerifyCodeCache

type VerifyCodeCache interface {
	// Set storage code into cache with ttl, return false if retry failed.
	Set(ctx context.Context, usage auth.Usage, code, to string, ttl, retry time.Duration) (bool, error)
	// Get returns the specified code
	Get(ctx context.Context, usage auth.Usage, code string) (string, error)
	// Del remove the specified code from cache
	Del(ctx context.Context, usage auth.Usage, code string) error
}

VerifyCodeCache is responsible for storing verification code into cache

Jump to

Keyboard shortcuts

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