32 lines
741 B
Go
32 lines
741 B
Go
package universe_key_value
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type Capability uint8
|
|
|
|
const (
|
|
CapabilityTTL Capability = iota
|
|
)
|
|
|
|
type KeyValueProvider interface {
|
|
HasCapability(capability Capability) bool
|
|
|
|
ProvideBinary(prefix string) (KeyValueStoreBinary, error)
|
|
ProvideString(prefix string) (KeyValueStoreString, error)
|
|
}
|
|
|
|
type KeyValueStore[T any] interface {
|
|
HasCapability(capability Capability) bool
|
|
|
|
Get(ctx context.Context, key string) (T, error)
|
|
Set(ctx context.Context, key string, value T) error
|
|
SetWithExpiration(ctx context.Context, key string, value T, expiresAt time.Time) error
|
|
Remove(ctx context.Context, key string) error
|
|
}
|
|
|
|
type KeyValueStoreBinary KeyValueStore[[]byte]
|
|
type KeyValueStoreString KeyValueStore[string]
|