Documentation
¶
Index ¶
- type BytesCodec
- type CompressionCodec
- type JSONCodec
- type Option
- type StoreKey
- type StringCodec
- type ValueCodec
- type ValueEnvelope
- type ValueStore
- func (s *ValueStore[T]) Delete(ctx context.Context, key StoreKey) error
- func (s *ValueStore[T]) Exists(ctx context.Context, key StoreKey) (bool, error)
- func (s *ValueStore[T]) Get(ctx context.Context, key StoreKey) (T, bool, error)
- func (s *ValueStore[T]) Set(ctx context.Context, key StoreKey, value T, ttl time.Duration) error
- func (s *ValueStore[T]) SetIfAbsent(ctx context.Context, key StoreKey, value T, ttl time.Duration) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BytesCodec ¶
type BytesCodec struct{}
BytesCodec 用于存储原始字节切片。
func (BytesCodec) Name ¶
func (BytesCodec) Name() string
type CompressionCodec ¶
type CompressionCodec[T any] struct { // contains filtered or unexported fields }
CompressionCodec 使用 gzip 为基础 codec 增加压缩能力。
func NewCompressionCodec ¶
func NewCompressionCodec[T any](base ValueCodec[T]) CompressionCodec[T]
NewCompressionCodec 使用 gzip 包装一个基础 codec。
func (CompressionCodec[T]) Compressed ¶
func (CompressionCodec[T]) Compressed() bool
Compressed 返回当前 codec 是否输出压缩载荷。
func (CompressionCodec[T]) Marshal ¶
func (c CompressionCodec[T]) Marshal(value T) ([]byte, error)
func (CompressionCodec[T]) Name ¶
func (c CompressionCodec[T]) Name() string
func (CompressionCodec[T]) Unmarshal ¶
func (c CompressionCodec[T]) Unmarshal(payload []byte) (T, error)
type Option ¶
type Option[T any] func(*ValueStore[T])
func WithObserver ¶
func WithObserver[T any](observer observability.StoreObserver) Option[T]
WithObserver 配置 typed store 观测器。
type StringCodec ¶
type StringCodec struct{}
StringCodec 用于存储原始字符串。
func (StringCodec) Name ¶
func (StringCodec) Name() string
type ValueCodec ¶
type ValueCodec[T any] interface { Marshal(value T) ([]byte, error) Unmarshal(payload []byte) (T, error) Name() string }
ValueCodec 负责 typed value 的编解码。
type ValueEnvelope ¶
ValueEnvelope 描述 typed store 的载荷与写入元数据。
type ValueStore ¶
type ValueStore[T any] struct { // contains filtered or unexported fields }
ValueStore 是最小可复用的 typed Redis value store。
func NewValueStore ¶
func NewValueStore[T any](client goredis.UniversalClient, codec ValueCodec[T], opts ...Option[T]) *ValueStore[T]
NewValueStore 创建 typed Redis value store。
func (*ValueStore[T]) Delete ¶
func (s *ValueStore[T]) Delete(ctx context.Context, key StoreKey) error
Delete 从 Redis 中删除一个键。
func (*ValueStore[T]) SetIfAbsent ¶
func (s *ValueStore[T]) SetIfAbsent(ctx context.Context, key StoreKey, value T, ttl time.Duration) (bool, error)
SetIfAbsent 仅在键不存在时写入 typed value。
Click to show internal directories.
Click to hide internal directories.