v0.0.0-...-6a524e6 Latest Latest

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

Go to latest
Published: May 14, 2024 License: MIT Imports: 13 Imported by: 0




This section is empty.


View Source
var (
	ErrCartIsNil = errors.New("cart is nil")


This section is empty.


type CartSerializer

type CartSerializer interface {
	Serialize(c *cartDomain.Cart) ([]byte, error)
	Deserialize(b []byte) (*cartDomain.Cart, error)

CartSerializer serializes carts in order to store them in redis

type GobSerializer

type GobSerializer struct{}

GobSerializer serializes carts using gob

func (GobSerializer) Deserialize

func (gs GobSerializer) Deserialize(d []byte) (*cartDomain.Cart, error)

Deserialize a cart using gob

func (GobSerializer) Serialize

func (gs GobSerializer) Serialize(c *cartDomain.Cart) ([]byte, error)

Serialize a cart using gob

type RedisStorage

type RedisStorage struct {
	// contains filtered or unexported fields

RedisStorage stores carts in redis

func (*RedisStorage) GetCart

func (r *RedisStorage) GetCart(ctx context.Context, id string) (*cartDomain.Cart, error)

GetCart fetches a cart from redis and deserializes it

func (*RedisStorage) HasCart

func (r *RedisStorage) HasCart(ctx context.Context, id string) bool

HasCart checks if the cart id exists as a key in redis

func (*RedisStorage) Inject

func (r *RedisStorage) Inject(
	logger flamingo.Logger,
	serializer CartSerializer,
	config *struct {
		RedisKeyPrefix       string  `inject:"config:commerce.contrib.cart.redis.keyPrefix"`
		RedisTTLGuest        string  `inject:"config:commerce.contrib.cart.redis.ttl.guest"`
		RedisTTLCustomer     string  `inject:"config:commerce.contrib.cart.redis.ttl.customer"`
		RedisNetwork         string  `inject:""`
		RedisAddress         string  `inject:"config:commerce.contrib.cart.redis.address"`
		RedisPassword        string  `inject:"config:commerce.contrib.cart.redis.password"`
		RedisIdleConnections float64 `inject:"config:commerce.contrib.cart.redis.idleConnections"`
		RedisDatabase        int     `inject:"config:commerce.contrib.cart.redis.database,optional"`
		RedisTLS             bool    `inject:"config:commerce.contrib.cart.redis.tls,optional"`
) *RedisStorage

Inject dependencies and build redis client

func (*RedisStorage) RemoveCart

func (r *RedisStorage) RemoveCart(ctx context.Context, cart *cartDomain.Cart) error

RemoveCart deletes a cart from redis

func (*RedisStorage) Status

func (r *RedisStorage) Status() (alive bool, details string)

Status healthcheck via ping

func (*RedisStorage) StoreCart

func (r *RedisStorage) StoreCart(ctx context.Context, cart *cartDomain.Cart) error

StoreCart serializes a cart and stores it in redis

Jump to

Keyboard shortcuts

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