Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrKeyNotFound = errors.New("key not found")
Functions ¶
This section is empty.
Types ¶
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a concurrent, process-local Storage. Its zero value is ready for use.
func (*Memory) Delete ¶
Delete removes key and returns nil when it is absent.
If ctx is already done, Delete returns ctx.Err without changing storage.
func (*Memory) Get ¶
Get returns an independent copy of the value associated with key.
It returns ErrKeyNotFound when the key is missing or expired. If ctx is already done, Get returns ctx.Err without reading storage.
type Storage ¶
type Storage interface {
// Get returns the value associated with key.
//
// A missing or expired key must return an error that matches ErrKeyNotFound with errors.Is.
Get(ctx context.Context, key string) ([]byte, error)
// Set stores value under key and replaces any existing value.
//
// A positive expiration sets a time to live, while a zero or negative expiration keeps the value until it is replaced or deleted.
Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
// Delete removes key and returns nil when it is absent.
Delete(ctx context.Context, key string) error
}
Storage persists opaque session state and must be safe for concurrent use.
Implementations do not need compare-and-swap or distributed locking because a Bus serializes updates locally.
Click to show internal directories.
Click to hide internal directories.