Documentation ¶
Overview ¶
Package redis provides a Redis repository implementation for storing and managing refresh tokens.
Index ¶
- func NewRedis(ctx context.Context, config Config) (*redis.Client, error)
- type Config
- type RefreshTokenRepository
- func (r RefreshTokenRepository) DeleteRefreshToken(ctx context.Context, userID string, token domain.Token) error
- func (r RefreshTokenRepository) DeleteRefreshTokens(ctx context.Context, userID string, tokens []domain.Token) error
- func (r RefreshTokenRepository) GetRefreshToken(ctx context.Context, userID string, token domain.Token) (domain.Token, error)
- func (r RefreshTokenRepository) GetRefreshTokens(ctx context.Context, userID string) ([]domain.Token, error)
- func (r RefreshTokenRepository) SaveRefreshToken(ctx context.Context, userID string, token domain.Token) error
- func (r RefreshTokenRepository) SaveRefreshTokens(ctx context.Context, userID string, tokens []domain.Token) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.