storage

package
v0.0.0-...-17b2b45 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrItemNotFound = errors.New("item not found")
)

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Set(id string, item Item) error
	Retreive(id string) (*Item, error)
	Remove(id string) error
}

type CacheClient

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

func NewCacheClient

func NewCacheClient(cache *ristretto.Cache) *CacheClient

func (*CacheClient) Remove

func (c *CacheClient) Remove(id string) error

func (*CacheClient) Retreive

func (c *CacheClient) Retreive(id string) (*Item, error)

func (*CacheClient) Set

func (c *CacheClient) Set(id string, item Item) error

type Item

type Item struct {
	ID          string    `json:"id" db:"id"`
	Name        string    `json:"name" db:"name"`
	Description string    `json:"description" db:"description"`
	Price       float64   `json:"price" db:"price"`
	CreatedAt   time.Time `json:"created_at" db:"created_at"`
	UpdatedAt   time.Time `json:"updated_at" db:"updated_at"`
}

type ProccessMessageFunc

type ProccessMessageFunc func(ctx context.Context, id string, values map[string]interface{}) error

ProccessMessageFunc is a function that processes a message from Redis

type SqlClient

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

func NewSqlClient

func NewSqlClient(db *sqlx.DB) *SqlClient

func (*SqlClient) GetItem

func (s *SqlClient) GetItem(ctx context.Context, id string) (*Item, error)

func (*SqlClient) UpsertItem

func (s *SqlClient) UpsertItem(ctx context.Context, item Item) (*Item, error)

type StorageClient

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

func NewStorageClient

func NewStorageClient(sql *SqlClient, cache Cache) *StorageClient

func (*StorageClient) GetItem

func (s *StorageClient) GetItem(ctx context.Context, id string) (*Item, error)

func (*StorageClient) ProcessCacheInvalidationMessage

func (s *StorageClient) ProcessCacheInvalidationMessage(ctx context.Context, msgID string, values map[string]interface{}) error

func (*StorageClient) UpsertItem

func (s *StorageClient) UpsertItem(ctx context.Context, item Item) (*Item, error)

type StreamProcessor

type StreamProcessor struct {
	StreamName string
	// contains filtered or unexported fields
}

StreamProcessor is a struct that processes messages from Redis

func NewStreamProcessor

func NewStreamProcessor(streamName string, redis *redis.Client) *StreamProcessor

func (*StreamProcessor) Run

func (p *StreamProcessor) Run(ctx context.Context, processMessage ProccessMessageFunc) error

Run function to process messages from Redis one by one

Jump to

Keyboard shortcuts

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