redis

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TTLNotTakenInto = time.Duration(0)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

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

Storage implements a data.Storage interface using a map stored in memory.

func NewStorage

func NewStorage(
	rdb redis.UniversalClient,
	ttl time.Duration,
	dbPrefix string,
) (*Storage, error)

NewStorage creates an instance of the Storage structure with Redis client instance.

func (*Storage) Iterate

func (s *Storage) Iterate(
	ctx context.Context,
	tmpl data.Object,
	pref data.Prefix,
) (data.Iterator, error)

Iterate does what Search does, but in place of the finished collection of objects an iterator will be returned that can be used to list the objects one by one. The original object is only needed as a template, other instances will be created based on it (by method Copy), but the object itself will not be changed.

func (*Storage) Load

func (s *Storage) Load(
	ctx context.Context,
	obj data.Object,
	key data.Key,
) error

Load loads an object from the repository, using Key as a unique name (path) to find the object and Type (by calling the Instance method). The UnmarshalBinary method can be called for the object. To restore an object, you must allocate memory for it to avoid panic when working with a nil address. If the object is not found, an ErrObjectNotFound error will be returned.

func (*Storage) Save

func (s *Storage) Save(
	ctx context.Context,
	obj data.Object,
	key data.Key,
) error

Save stores the object in a storage, using Key as the unique name (path) to save the object and Type (by calling Instance method) to share the namespace between objects. Key can be repeated for different Type values. The MarshalBinary method can be called before the object is saved.

func (*Storage) SaveConsideringTTL

func (s *Storage) SaveConsideringTTL(
	ctx context.Context,
	obj data.Object,
	key data.Key,
	ttl time.Duration,
) error

func (*Storage) Search

func (s *Storage) Search(
	ctx context.Context,
	tmpl data.Object,
	pref data.Prefix,
) ([]data.Object, error)

Search searches for objects in the repository of a certain Type. It returns a list of found objects or ErrObjectNotFound if no objects matching the criteria were found. Prefix is used for additional filtering of objects according to their Key with partial match at the beginning of the key. If you want to get all objects Prefix can be empty. The original object is only needed as a template, other instances will be created based on it (by method Copy), but the object itself will not be changed.

func (*Storage) TTL

func (s *Storage) TTL() time.Duration

Jump to

Keyboard shortcuts

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