redisx

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataSource

type DataSource interface {
	WithTTL(ttl time.Duration) DataSourceBuilder

	// Record CRUD (stored as JSON string)
	Create(ctx context.Context, key string, value any) error
	Update(ctx context.Context, key string, value any) error
	Delete(ctx context.Context, key string) error
	Get(ctx context.Context, key string, dest any) error

	// Index operations
	AddToIndex(ctx context.Context, indexKey, id string, score float64) error
	RemoveFromIndex(ctx context.Context, indexKey, id string) error
	GetAllFromIndex(ctx context.Context, indexKey string, start, stop int64) ([]string, error)

	// Atomic helpers (production-safe)
	UpsertWithIndex(ctx context.Context, key, indexKey, id string, score float64, value any, ttl time.Duration) error
	DeleteWithIndex(ctx context.Context, key, indexKey, id string) error

	// Bulk read
	GetAll(ctx context.Context, indexKey string, destSlice any) error
}

func NewDataSource

func NewDataSource(rdb *redis.Client) DataSource

type DataSourceBuilder

type DataSourceBuilder interface {
	Create(ctx context.Context, key string, value any) error
	Update(ctx context.Context, key string, value any) error
	AddToIndex(ctx context.Context, indexKey, id string, score float64) error
	UpsertWithIndex(ctx context.Context, key, indexKey, id string, score float64, value any) error
}

type Repository

type Repository[T any] struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository[T any](
	ds DataSource,
	name string,
	env string,
	getIDFn func(*T) string,
) *Repository[T]

func (*Repository[T]) Create

func (s *Repository[T]) Create(ctx context.Context, obj *T) error

func (*Repository[T]) Delete

func (s *Repository[T]) Delete(ctx context.Context, id string) error

func (*Repository[T]) FindList

func (s *Repository[T]) FindList(ctx context.Context) ([]T, error)

func (*Repository[T]) FindOne

func (s *Repository[T]) FindOne(ctx context.Context, id string) (*T, error)

func (*Repository[T]) Update

func (s *Repository[T]) Update(ctx context.Context, obj *T) error

func (*Repository[T]) WithTTL

func (s *Repository[T]) WithTTL(ttl time.Duration) *Repository[T]

Jump to

Keyboard shortcuts

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