Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeEnvelope(raw []byte) (version, expiresAtUnix int64, value []byte, ok bool)
- func EncodeEnvelope(version, expiresAtUnix int64, value []byte) []byte
- func ExpiryFromTtl(ttlSeconds int) int64
- func Get[T any](ctx context.Context, ds DataStore, key []byte, codec Codec[T]) (value T, found bool, err error)
- func IsExpired(expiresAtUnix int64) bool
- func Put[T any](ctx context.Context, ds DataStore, key []byte, value T, codec Codec[T], ...) error
- func RegionUsage(m MultiDataStore, majorKey, region string) int64
- func StartSweeper(ds DataStore, interval time.Duration, onError ...func(error)) (stop func(), err error)
- func TtlFromExpiry(expiresAtUnix int64) int
- func Usage(m MultiDataStore, majorKey string) int64
- func WithTransaction(ctx context.Context, beanName string, tx Transaction) context.Context
- type BatchOperation
- func (t *BatchOperation) Add(entry RawEntry) *BatchOperation
- func (t *BatchOperation) Do() error
- func (t *BatchOperation) Len() int
- func (t *BatchOperation) Put(key, value []byte, ttlSeconds int) *BatchOperation
- func (t *BatchOperation) PutCounter(value uint64, ttlSeconds int, formatKey string, args ...interface{}) *BatchOperation
- func (t *BatchOperation) PutProto(msg proto.Message, ttlSeconds int, formatKey string, args ...interface{}) error
- func (t *BatchOperation) PutString(value string, ttlSeconds int, formatKey string, args ...interface{}) *BatchOperation
- type Capability
- type Codec
- type CompareAndSetOperation
- func (t *CompareAndSetOperation) Binary(value []byte) (bool, error)
- func (t *CompareAndSetOperation) ByKey(formatKey string, args ...interface{}) *CompareAndSetOperation
- func (t *CompareAndSetOperation) ByRawKey(key []byte) *CompareAndSetOperation
- func (t *CompareAndSetOperation) Counter(value uint64) (bool, error)
- func (t *CompareAndSetOperation) Proto(msg proto.Message) (bool, error)
- func (t *CompareAndSetOperation) String(value string) (bool, error)
- func (t *CompareAndSetOperation) WithTtl(ttlSeconds int) *CompareAndSetOperation
- func (t *CompareAndSetOperation) WithVersion(version int64) *CompareAndSetOperation
- type CounterEntry
- type DataStore
- type DataStoreManager
- type EnumerateOperation
- func (t *EnumerateOperation) After(token []byte) *EnumerateOperation
- func (t *EnumerateOperation) ByPrefix(formatPrefix string, args ...interface{}) *EnumerateOperation
- func (t *EnumerateOperation) ByRawPrefix(prefix []byte) *EnumerateOperation
- func (t *EnumerateOperation) Do(cb func(*RawEntry) bool) error
- func (t *EnumerateOperation) DoCounters(cb func(*CounterEntry) bool) (err error)
- func (t *EnumerateOperation) DoPage(cb func(*RawEntry) bool) (next []byte, err error)
- func (t *EnumerateOperation) DoProto(factory func() proto.Message, cb func(*ProtoEntry) bool) error
- func (t *EnumerateOperation) Limit(n int) *EnumerateOperation
- func (t *EnumerateOperation) OnlyKeys() *EnumerateOperation
- func (t *EnumerateOperation) Range(from, to []byte) *EnumerateOperation
- func (t *EnumerateOperation) Reverse() *EnumerateOperation
- func (t *EnumerateOperation) Seek(formatSeek string, args ...interface{}) *EnumerateOperation
- func (t *EnumerateOperation) WithBatchSize(batchSize int) *EnumerateOperation
- type GetOperation
- func (t *GetOperation) ByKey(formatKey string, args ...interface{}) *GetOperation
- func (t *GetOperation) ByRawKey(key []byte) *GetOperation
- func (t *GetOperation) Required() *GetOperation
- func (t *GetOperation) ToBinary() ([]byte, error)
- func (t *GetOperation) ToCounter() (uint64, error)
- func (t *GetOperation) ToCounterEntry() (entry CounterEntry, err error)
- func (t *GetOperation) ToEntry() (entry RawEntry, err error)
- func (t *GetOperation) ToProto(container proto.Message) error
- func (t *GetOperation) ToProtoEntry(factory func() proto.Message) (entry ProtoEntry, err error)
- func (t *GetOperation) ToString() (string, error)
- func (t *GetOperation) WithTtl(ttl *int) *GetOperation
- func (t *GetOperation) WithVersion(version *int64) *GetOperation
- type IncrementOperation
- func (t *IncrementOperation) ByKey(formatKey string, args ...interface{}) *IncrementOperation
- func (t *IncrementOperation) ByRawKey(key []byte) *IncrementOperation
- func (t *IncrementOperation) Do() (prev int64, err error)
- func (t *IncrementOperation) WithDelta(delta int64) *IncrementOperation
- func (t *IncrementOperation) WithInitialValue(initial int64) *IncrementOperation
- func (t *IncrementOperation) WithTtl(ttlSeconds int) *IncrementOperation
- type KeyStrategy
- type ManagedDataStore
- type ManagedTransactionalDataStore
- type MultiDataStore
- type ProtoEntry
- type RawEntry
- type RemoveOperation
- type SetOperation
- func (t *SetOperation) Binary(value []byte) error
- func (t *SetOperation) ByKey(formatKey string, args ...interface{}) *SetOperation
- func (t *SetOperation) ByRawKey(key []byte) *SetOperation
- func (t *SetOperation) Counter(value uint64) error
- func (t *SetOperation) Proto(msg proto.Message) error
- func (t *SetOperation) String(value string) error
- func (t *SetOperation) WithTtl(ttlSeconds int) *SetOperation
- type StripedMutex
- type Sweepable
- type TouchOperation
- type Transaction
- type TransactionalDataStore
- type TransactionalManager
- type Typed
- func (t Typed[T]) Enumerate(ctx context.Context, prefix []byte, cb func(key []byte, value T) bool) error
- func (t Typed[T]) Get(ctx context.Context, key []byte) (T, bool, error)
- func (t Typed[T]) Put(ctx context.Context, key []byte, value T, ttlSeconds int) error
- func (t Typed[T]) Remove(ctx context.Context, key []byte) error
- type WatchEvent
- type WatchEventType
- type WatchHub
- type WatchOperation
Constants ¶
const EnvelopeHeaderLen = 1 + 8 + 8
EnvelopeHeaderLen is the fixed size of the envelope header in bytes.
const NoExpiry = -1
NoExpiry, passed as a TTL, pins a record: it overrides any region default TTL so the record never expires. (Distinct from NoTTL/0, which means "unspecified" and therefore takes the region default when one is configured.)
const NoTTL = 0
* Marker that TTL (time-to-live in seconds) is not defined, therefore not setup, meaning eternal record
const SystemRegion = "_system"
SystemRegion holds a major key's own bookkeeping (usage counters, manifests). It is never metered (that would count the meter's own writes).
Variables ¶
var ( ErrNotFound = os.ErrNotExist // ErrInvalidRequest is returned if the user request is invalid. ErrInvalidRequest = xerrors.New("invalid request") // ErrConcurrentTransaction is returned when a transaction conflicts with another transaction. ErrConcurrentTxn = xerrors.New("concurrent transaction, try again") // ErrReadOnlyTxn is returned if an update function is called on a read-only transaction. ErrReadOnlyTxn = xerrors.New("read-only transaction has update operation") // ErrDiscardedTxn is returned if a previously discarded transaction is re-used. ErrDiscardedTxn = xerrors.New("transaction has been discarded") // ErrCanceledTxn is returned if user canceled transaction. ErrCanceledTxn = xerrors.New("transaction has been canceled") // ErrTooBigTxn is returned if too many writes are fit into a single transaction. ErrTooBigTxn = xerrors.New("transaction is too big") // ErrEmptyKey is returned if an empty key is passed on an update function. ErrEmptyKey = xerrors.New("empty key") // ErrInvalidKey is returned if the key has wrong character(s) ErrInvalidKey = xerrors.New("key is invalid") // ErrAlreadyClosed is returned when store is already closed ErrAlreadyClosed = xerrors.New("already closed") // ErrInternal ErrInternal = xerrors.New("internal error") // ErrNotSupported is returned when an operation is not supported by the backend capabilities. ErrNotSupported = xerrors.New("operation not supported by this store") )
var DataStoreClass = reflect.TypeOf((*DataStore)(nil)).Elem()
var DataStoreManagerClass = reflect.TypeOf((*DataStoreManager)(nil)).Elem()
var DefaultBatchSize = 256
* Default batch size, could be overwritten
var ManagedDataStoreClass = reflect.TypeOf((*ManagedDataStore)(nil)).Elem()
var ManagedTransactionalDataStoreClass = reflect.TypeOf((*ManagedTransactionalDataStore)(nil)).Elem()
var MultiDataStoreClass = reflect.TypeOf((*MultiDataStore)(nil)).Elem()
var SweepableClass = reflect.TypeOf((*Sweepable)(nil)).Elem()
var TransactionClass = reflect.TypeOf((*Transaction)(nil)).Elem()
var TransactionalDataStoreClass = reflect.TypeOf((*TransactionalDataStore)(nil)).Elem()
var TransactionalManagerClass = reflect.TypeOf((*TransactionalManager)(nil)).Elem()
var WatchBufferSize = 256
WatchBufferSize is the per-subscriber channel buffer used by WatchHub.
Functions ¶
func DecodeEnvelope ¶
DecodeEnvelope unwraps an envelope. If raw is not an envelope (legacy value), it returns ok=false with the original bytes as the value and zero metadata. The returned value aliases raw; copy it if it must outlive raw's storage.
func EncodeEnvelope ¶
EncodeEnvelope wraps value with version and expiry metadata.
func ExpiryFromTtl ¶
ExpiryFromTtl converts a relative ttl (seconds) into an absolute unix timestamp. ttlSeconds <= 0 (NoTTL) yields 0, meaning no expiry.
func Get ¶
func Get[T any](ctx context.Context, ds DataStore, key []byte, codec Codec[T]) (value T, found bool, err error)
Get loads and decodes the value at key. found is false (with the zero T) when the key is absent.
func Put ¶
func Put[T any](ctx context.Context, ds DataStore, key []byte, value T, codec Codec[T], ttlSeconds int) error
Put encodes and stores value at key with the given ttl (NoTTL for none).
func RegionUsage ¶ added in v1.4.0
func RegionUsage(m MultiDataStore, majorKey, region string) int64
RegionUsage returns a major key's live byte footprint for one region.
func StartSweeper ¶
func TtlFromExpiry ¶
TtlFromExpiry converts an absolute expiry timestamp into the remaining ttl in seconds. It returns NoTTL (0) when there is no expiry; a value with an expiry that has essentially no time left reports -1 to stay distinguishable from NoTTL.
func Usage ¶ added in v1.4.0
func Usage(m MultiDataStore, majorKey string) int64
Usage returns a major key's total live byte footprint recorded by WithMetering (0 when unmetered or empty).
func WithTransaction ¶
Types ¶
type BatchOperation ¶
type BatchOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
// contains filtered or unexported fields
}
BatchOperation accumulates entries and writes them in one SetBatchRaw call. The batch is atomic only on stores reporting BatchAtomicCapability.
func (*BatchOperation) Add ¶
func (t *BatchOperation) Add(entry RawEntry) *BatchOperation
Add appends a pre-built entry (Key, Value, Ttl are used).
func (*BatchOperation) Do ¶
func (t *BatchOperation) Do() error
Do writes all accumulated entries via SetBatchRaw.
func (*BatchOperation) Len ¶
func (t *BatchOperation) Len() int
Len returns the number of accumulated entries.
func (*BatchOperation) Put ¶
func (t *BatchOperation) Put(key, value []byte, ttlSeconds int) *BatchOperation
Put appends a binary key/value with optional ttl (NoTTL for none).
func (*BatchOperation) PutCounter ¶
func (t *BatchOperation) PutCounter(value uint64, ttlSeconds int, formatKey string, args ...interface{}) *BatchOperation
PutCounter appends a uint64 counter value under a formatted key.
func (*BatchOperation) PutProto ¶
func (t *BatchOperation) PutProto(msg proto.Message, ttlSeconds int, formatKey string, args ...interface{}) error
PutProto appends a marshaled protobuf message under a formatted key.
func (*BatchOperation) PutString ¶
func (t *BatchOperation) PutString(value string, ttlSeconds int, formatKey string, args ...interface{}) *BatchOperation
PutString appends a string value under a formatted key.
type Capability ¶
type Capability uint64
const ( // TTLCapability means SetRaw/TouchRaw honor ttlSeconds and entries expire. TTLCapability Capability = 1 << iota // AtomicCapability means CompareAndSetRaw and IncrementRaw are atomic and // version-aware (GetRaw returns a meaningful, changing Version). AtomicCapability // TransactionCapability means the store implements TransactionalManager. TransactionCapability // EncryptedCapability means values are encrypted at rest. EncryptedCapability // OrderedCapability means EnumerateRaw returns keys in sorted (lexical) order. OrderedCapability // WatchCapability means WatchRaw delivers change notifications. WatchCapability // BatchAtomicCapability means SetBatchRaw is all-or-nothing (a failed batch // leaves no partial writes). Without it, SetBatchRaw is still correct but a // failure mid-way may leave some entries written. BatchAtomicCapability )
func (Capability) Has ¶
func (c Capability) Has(other Capability) bool
Has reports whether all the bits in other are set in c.
func (Capability) String ¶
func (c Capability) String() string
String renders the capability set as a pipe-separated list, e.g. "TTL|Atomic|Ordered".
type Codec ¶
Codec encodes/decodes values of type T to and from the stored byte form.
type CompareAndSetOperation ¶
type CompareAndSetOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
// contains filtered or unexported fields
}
func (*CompareAndSetOperation) Binary ¶
func (t *CompareAndSetOperation) Binary(value []byte) (bool, error)
func (*CompareAndSetOperation) ByKey ¶
func (t *CompareAndSetOperation) ByKey(formatKey string, args ...interface{}) *CompareAndSetOperation
func (*CompareAndSetOperation) ByRawKey ¶
func (t *CompareAndSetOperation) ByRawKey(key []byte) *CompareAndSetOperation
func (*CompareAndSetOperation) Counter ¶
func (t *CompareAndSetOperation) Counter(value uint64) (bool, error)
func (*CompareAndSetOperation) Proto ¶
func (t *CompareAndSetOperation) Proto(msg proto.Message) (bool, error)
func (*CompareAndSetOperation) String ¶
func (t *CompareAndSetOperation) String(value string) (bool, error)
func (*CompareAndSetOperation) WithTtl ¶
func (t *CompareAndSetOperation) WithTtl(ttlSeconds int) *CompareAndSetOperation
func (*CompareAndSetOperation) WithVersion ¶
func (t *CompareAndSetOperation) WithVersion(version int64) *CompareAndSetOperation
type DataStore ¶
type DataStore interface {
glue.DisposableBean
glue.NamedBean
Features() Capability
Get(ctx context.Context) *GetOperation
Set(ctx context.Context) *SetOperation
Batch(ctx context.Context) *BatchOperation
// equivalent of i++ operation, always returns previous value
Increment(ctx context.Context) *IncrementOperation
CompareAndSet(ctx context.Context) *CompareAndSetOperation
Touch(ctx context.Context) *TouchOperation
Remove(ctx context.Context) *RemoveOperation
Enumerate(ctx context.Context) *EnumerateOperation
Watch(ctx context.Context) *WatchOperation
GetRaw(ctx context.Context, key []byte, ttlPtr *int, versionPtr *int64, required bool) ([]byte, error)
SetRaw(ctx context.Context, key, value []byte, ttlSeconds int) error
SetBatchRaw(ctx context.Context, entries []RawEntry) error
CompareAndSetRaw(ctx context.Context, key, value []byte, ttlSeconds int, version int64) (bool, error)
IncrementRaw(ctx context.Context, key []byte, initial, delta int64, ttlSeconds int) (int64, error)
TouchRaw(ctx context.Context, key []byte, ttlSeconds int) error
RemoveRaw(ctx context.Context, key []byte) error
EnumerateRaw(ctx context.Context, prefix, seek []byte, batchSize int, onlyKeys bool, reverse bool, cb func(*RawEntry) bool) error
WatchRaw(ctx context.Context, prefix []byte, cb func(*WatchEvent) bool) error
}
type DataStoreManager ¶
type EnumerateOperation ¶
type EnumerateOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
// contains filtered or unexported fields
}
func (*EnumerateOperation) After ¶
func (t *EnumerateOperation) After(token []byte) *EnumerateOperation
After resumes enumeration strictly after the given continuation token (the last key from a previous page). A nil/empty token starts from the beginning.
func (*EnumerateOperation) ByPrefix ¶
func (t *EnumerateOperation) ByPrefix(formatPrefix string, args ...interface{}) *EnumerateOperation
func (*EnumerateOperation) ByRawPrefix ¶
func (t *EnumerateOperation) ByRawPrefix(prefix []byte) *EnumerateOperation
func (*EnumerateOperation) Do ¶
func (t *EnumerateOperation) Do(cb func(*RawEntry) bool) error
Do enumerates all matching entries (honoring Range/After/Limit if set).
func (*EnumerateOperation) DoCounters ¶
func (t *EnumerateOperation) DoCounters(cb func(*CounterEntry) bool) (err error)
func (*EnumerateOperation) DoPage ¶
func (t *EnumerateOperation) DoPage(cb func(*RawEntry) bool) (next []byte, err error)
DoPage is like Do but returns an opaque continuation token to pass to After for the next page. The token is nil when the range has been exhausted.
func (*EnumerateOperation) DoProto ¶
func (t *EnumerateOperation) DoProto(factory func() proto.Message, cb func(*ProtoEntry) bool) error
func (*EnumerateOperation) Limit ¶
func (t *EnumerateOperation) Limit(n int) *EnumerateOperation
Limit caps the number of entries returned by Do/DoPage (a page size).
func (*EnumerateOperation) OnlyKeys ¶
func (t *EnumerateOperation) OnlyKeys() *EnumerateOperation
func (*EnumerateOperation) Range ¶
func (t *EnumerateOperation) Range(from, to []byte) *EnumerateOperation
Range restricts enumeration to the half-open key interval [from, to): from is inclusive (the start position), to is exclusive (nil means unbounded). Requires an ordered store (OrderedCapability), otherwise Do/DoPage return ErrNotSupported.
func (*EnumerateOperation) Reverse ¶
func (t *EnumerateOperation) Reverse() *EnumerateOperation
func (*EnumerateOperation) Seek ¶
func (t *EnumerateOperation) Seek(formatSeek string, args ...interface{}) *EnumerateOperation
func (*EnumerateOperation) WithBatchSize ¶
func (t *EnumerateOperation) WithBatchSize(batchSize int) *EnumerateOperation
type GetOperation ¶
type GetOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
// contains filtered or unexported fields
}
func (*GetOperation) ByKey ¶
func (t *GetOperation) ByKey(formatKey string, args ...interface{}) *GetOperation
func (*GetOperation) ByRawKey ¶
func (t *GetOperation) ByRawKey(key []byte) *GetOperation
func (*GetOperation) Required ¶
func (t *GetOperation) Required() *GetOperation
func (*GetOperation) ToBinary ¶
func (t *GetOperation) ToBinary() ([]byte, error)
func (*GetOperation) ToCounter ¶
func (t *GetOperation) ToCounter() (uint64, error)
func (*GetOperation) ToCounterEntry ¶
func (t *GetOperation) ToCounterEntry() (entry CounterEntry, err error)
func (*GetOperation) ToEntry ¶
func (t *GetOperation) ToEntry() (entry RawEntry, err error)
func (*GetOperation) ToProtoEntry ¶
func (t *GetOperation) ToProtoEntry(factory func() proto.Message) (entry ProtoEntry, err error)
func (*GetOperation) ToString ¶
func (t *GetOperation) ToString() (string, error)
func (*GetOperation) WithTtl ¶
func (t *GetOperation) WithTtl(ttl *int) *GetOperation
func (*GetOperation) WithVersion ¶
func (t *GetOperation) WithVersion(version *int64) *GetOperation
type IncrementOperation ¶
type IncrementOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
Initial int64
Delta int64 // should be initialized by 1
// contains filtered or unexported fields
}
func (*IncrementOperation) ByKey ¶
func (t *IncrementOperation) ByKey(formatKey string, args ...interface{}) *IncrementOperation
func (*IncrementOperation) ByRawKey ¶
func (t *IncrementOperation) ByRawKey(key []byte) *IncrementOperation
func (*IncrementOperation) Do ¶
func (t *IncrementOperation) Do() (prev int64, err error)
func (*IncrementOperation) WithDelta ¶
func (t *IncrementOperation) WithDelta(delta int64) *IncrementOperation
func (*IncrementOperation) WithInitialValue ¶
func (t *IncrementOperation) WithInitialValue(initial int64) *IncrementOperation
func (*IncrementOperation) WithTtl ¶
func (t *IncrementOperation) WithTtl(ttlSeconds int) *IncrementOperation
type KeyStrategy ¶ added in v1.3.3
type KeyStrategy interface {
Prefix(majorKey, region string) []byte
TenantPrefix(majorKey string) []byte
}
func LenPrefix ¶ added in v1.3.3
func LenPrefix() KeyStrategy
LenPrefix returns the binary-safe KeyStrategy matching the consensusdb backing store's header convention:
[2B big-endian len][majorKey][2B big-endian len][region][minorKey]
No separator and no escaping, so any bytes are allowed in majorKey/region, with the minor key as the raw tail.
func Separator ¶ added in v1.3.3
func Separator(sep string) KeyStrategy
Separator returns the readable KeyStrategy "major<sep>region<sep>minor" — e.g. Separator(":") lays out "acme:USERS:alice". majorKey and region must not contain sep (the separator is not escaped); use LenPrefix for binary-safe names. An empty sep defaults to ":".
type ManagedDataStore ¶
type ManagedDataStore interface {
DataStore
DataStoreManager
Instance() interface{}
}
type ManagedTransactionalDataStore ¶
type ManagedTransactionalDataStore interface {
DataStore
DataStoreManager
TransactionalManager
}
type MultiDataStore ¶ added in v1.3.3
type MultiDataStore interface {
glue.DisposableBean
glue.NamedBean
Features() Capability
Region(majorKey, region string) DataStore
}
func NewMulti ¶ added in v1.3.3
func NewMulti(name string, inner DataStore, strategy KeyStrategy) MultiDataStore
func NewSharding ¶ added in v1.4.0
func NewSharding(name string, shards ...MultiDataStore) MultiDataStore
NewSharding routes major keys across shards. With a single shard it is a thin passthrough (the "sharding-ready, not yet sharded" configuration).
Each shard's BeanName is its routing identity, so it must be non-empty, unique, and stable across restarts and config edits — renaming a shard reassigns its major keys. Misconfiguration panics here, at wiring time, not on first use.
func WithMetering ¶ added in v1.4.0
func WithMetering(m MultiDataStore) MultiDataStore
WithMetering wraps m so every write outside SystemRegion adjusts the owner's live byte counters (total and per-region) in its SystemRegion.
func WithRegionTTL ¶ added in v1.4.0
func WithRegionTTL(m MultiDataStore, regionTTL map[string]int) MultiDataStore
WithRegionTTL wraps m so writes to a region named in regionTTL get that default TTL (seconds) unless the caller passes an explicit TTL or NoExpiry. Regions absent from the map are returned unchanged.
type RemoveOperation ¶
type RemoveOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
// contains filtered or unexported fields
}
func (*RemoveOperation) ByKey ¶
func (t *RemoveOperation) ByKey(formatKey string, args ...interface{}) *RemoveOperation
func (*RemoveOperation) ByRawKey ¶
func (t *RemoveOperation) ByRawKey(key []byte) *RemoveOperation
func (*RemoveOperation) Do ¶
func (t *RemoveOperation) Do() error
type SetOperation ¶
type SetOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
// contains filtered or unexported fields
}
func (*SetOperation) Binary ¶
func (t *SetOperation) Binary(value []byte) error
func (*SetOperation) ByKey ¶
func (t *SetOperation) ByKey(formatKey string, args ...interface{}) *SetOperation
func (*SetOperation) ByRawKey ¶
func (t *SetOperation) ByRawKey(key []byte) *SetOperation
func (*SetOperation) Counter ¶
func (t *SetOperation) Counter(value uint64) error
func (*SetOperation) String ¶
func (t *SetOperation) String(value string) error
func (*SetOperation) WithTtl ¶
func (t *SetOperation) WithTtl(ttlSeconds int) *SetOperation
type StripedMutex ¶
type StripedMutex struct {
// contains filtered or unexported fields
}
func (*StripedMutex) Lock ¶
func (t *StripedMutex) Lock(key []byte)
Lock locks the stripe owning key.
func (*StripedMutex) LockAll ¶
func (t *StripedMutex) LockAll() (unlock func())
LockAll locks every stripe (ascending) and returns the unlock function. Used by whole-store operations such as DropAll.
func (*StripedMutex) LockMany ¶
func (t *StripedMutex) LockMany(keys ...[]byte) (unlock func())
LockMany locks the distinct stripes owning the given keys in ascending order and returns the unlock function (release in reverse order).
func (*StripedMutex) Unlock ¶
func (t *StripedMutex) Unlock(key []byte)
Unlock unlocks the stripe owning key.
type TouchOperation ¶
type TouchOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
// contains filtered or unexported fields
}
func (*TouchOperation) ByKey ¶
func (t *TouchOperation) ByKey(formatKey string, args ...interface{}) *TouchOperation
func (*TouchOperation) ByRawKey ¶
func (t *TouchOperation) ByRawKey(key []byte) *TouchOperation
func (*TouchOperation) Do ¶
func (t *TouchOperation) Do() error
func (*TouchOperation) WithTtl ¶
func (t *TouchOperation) WithTtl(ttlSeconds int) *TouchOperation
type Transaction ¶
func GetTransaction ¶
func GetTransaction(ctx context.Context, beanName string) (Transaction, bool)
func NewInnerTransaction ¶
func NewInnerTransaction(parent Transaction) Transaction
type TransactionalDataStore ¶
type TransactionalDataStore interface {
DataStore
TransactionalManager
}
type TransactionalManager ¶
type Typed ¶
type Typed[T any] struct { // contains filtered or unexported fields }
Typed binds a DataStore and a Codec[T] for ergonomic repeated typed access.
func (Typed[T]) Enumerate ¶
func (t Typed[T]) Enumerate(ctx context.Context, prefix []byte, cb func(key []byte, value T) bool) error
Enumerate decodes every value under prefix, invoking cb until it returns false.
type WatchEvent ¶
type WatchEvent struct {
Key []byte
Value []byte // nil for WatchDelete
Type WatchEventType
Version int64
}
WatchEvent is delivered by WatchRaw for each change matching the watched prefix.
type WatchEventType ¶
type WatchEventType int
const ( // WatchSet indicates a key was created or updated. WatchSet WatchEventType = iota // WatchDelete indicates a key was removed (or expired). WatchDelete )
func (WatchEventType) String ¶
func (t WatchEventType) String() string
type WatchHub ¶
type WatchHub struct {
// contains filtered or unexported fields
}
func NewWatchHub ¶
func NewWatchHub() *WatchHub
func (*WatchHub) Notify ¶
func (t *WatchHub) Notify(event *WatchEvent)
Notify fans an event out to every subscriber whose prefix matches the key.
type WatchOperation ¶
type WatchOperation struct {
DataStore // should be initialized
Context context.Context // should be initialized
// contains filtered or unexported fields
}
func (*WatchOperation) ByPrefix ¶
func (t *WatchOperation) ByPrefix(formatPrefix string, args ...interface{}) *WatchOperation
func (*WatchOperation) ByRawPrefix ¶
func (t *WatchOperation) ByRawPrefix(prefix []byte) *WatchOperation
func (*WatchOperation) Do ¶
func (t *WatchOperation) Do(cb func(*WatchEvent) bool) error
Do blocks delivering events to cb until cb returns false or the context is cancelled. A nil/empty prefix watches every key.