redisrepo

package
v0.0.0-...-bd94320 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisRepository

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

RedisRepository used to save and get metadata from redis cache. Must be initialized with New function.

func New

func New(ctx context.Context, settings Settings) (*RedisRepository, error)

New creates a new RedisRepository instance.

It takes a context.Context, and Settings to initialize the repository.

It creates a RedisRepository using the given settings, parses the connection string, creates a redis client, tests the connection, and returns the pointer to created RedisRepository and an error.

It returns the pointer to created RedisRepository and an error.

func (RedisRepository) GetUserCache

func (r RedisRepository) GetUserCache(
	ctx context.Context,
	id uuid.UUID,
) ([]models.Metadata, error)

GetUserCache gets the cached metadata for a user based on the user ID. It constructs the cache key using the user ID and retrieves the corresponding entry from the cache. If the entry is not found, it returns an apperrors.ErrNotFound error. If the retrieval fails, it returns the error. If the retrieval is successful, it unmarshals the retrieved data to a slice of models.Metadata and returns it.

func (RedisRepository) InvalidateUserCache

func (r RedisRepository) InvalidateUserCache(ctx context.Context, id uuid.UUID) error

InvalidateUserCache removes the cached metadata for a user based on the user ID. It constructs the cache key using the user ID and deletes the corresponding entry from the cache. Returns an error if the deletion fails.

func (RedisRepository) SaveUserCache

func (r RedisRepository) SaveUserCache(
	ctx context.Context,
	id uuid.UUID,
	meta []models.Metadata,
) error

SaveUserCache saves the metadata for a user in the Redis cache. It constructs the cache key using the user ID, marshals the metadata to JSON, and stores it in the cache with a specified TTL. Returns an error if marshaling fails or if saving to the cache encounters an error.

type Settings

type Settings struct {
	ConnectionString string
	TTL              time.Duration
}

Settings used to create RedisRepository. ConnectionString and TTL are required. Must be used with New function.

Jump to

Keyboard shortcuts

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