redis

package
v0.0.0-...-f767cfc Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package redis provides a Redis repository implementation for storing and managing refresh tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedis

func NewRedis(ctx context.Context, config Config) (*redis.Client, error)

NewRedis creates a new Redis db with the given configuration options.

If the context is canceled before the db is created, an error is returned. If "PING" command fails returns an error.

Types

type Config

type Config struct {
	Addr     string // Addr is the Redis server address (e.g. "localhost:6379").
	Password string // Password is the Redis server password (leave blank if none).
	DB       int    // DB is the Redis database number to use (default is 0).
}

Config represents the configuration options for the Redis db.

type RefreshTokenRepository

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

RefreshTokenRepository is a Redis repository for managing refresh tokens.

func NewRefreshTokenRepository

func NewRefreshTokenRepository(db *redis.Client) (*RefreshTokenRepository, error)

NewRefreshTokenRepository creates a new RefreshTokenRepository with the provided Redis db.

Returns an error if the db is nil.

func (RefreshTokenRepository) DeleteRefreshToken

func (r RefreshTokenRepository) DeleteRefreshToken(ctx context.Context, userID string, token domain.Token) error

DeleteRefreshToken removes a single refresh token for the given user ID.

If the specified token cannot be found, an error of type `refresh.ErrTokenNotFound` is returned.

func (RefreshTokenRepository) DeleteRefreshTokens

func (r RefreshTokenRepository) DeleteRefreshTokens(ctx context.Context, userID string, tokens []domain.Token) error

DeleteRefreshTokens removes the given refresh tokens associated with the specified user ID.

If any of the tokens cannot be found, this method returns an error of type `refresh.ErrTokenNotFound`.

func (RefreshTokenRepository) GetRefreshToken

func (r RefreshTokenRepository) GetRefreshToken(ctx context.Context, userID string, token domain.Token) (domain.Token, error)

GetRefreshToken returns the refresh token for the specified user ID and token value.

If the token is not found, an error value of `refresh.ErrTokenNotFound` is returned.

func (RefreshTokenRepository) GetRefreshTokens

func (r RefreshTokenRepository) GetRefreshTokens(ctx context.Context, userID string) ([]domain.Token, error)

GetRefreshTokens returns a slice of all the refresh tokens associated with the given user ID.

If no tokens are found, this method returns an error of type `refresh.ErrTokenNotFound`.

func (RefreshTokenRepository) SaveRefreshToken

func (r RefreshTokenRepository) SaveRefreshToken(ctx context.Context, userID string, token domain.Token) error

SaveRefreshToken saves the given refresh token associated with the specified user ID.

func (RefreshTokenRepository) SaveRefreshTokens

func (r RefreshTokenRepository) SaveRefreshTokens(ctx context.Context, userID string, tokens []domain.Token) error

SaveRefreshTokens saves the given refresh tokens associated with the specified user ID.

Jump to

Keyboard shortcuts

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