store

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BytesCodec

type BytesCodec struct{}

BytesCodec 用于存储原始字节切片。

func (BytesCodec) Marshal

func (BytesCodec) Marshal(value []byte) ([]byte, error)

func (BytesCodec) Name

func (BytesCodec) Name() string

func (BytesCodec) Unmarshal

func (BytesCodec) Unmarshal(payload []byte) ([]byte, error)

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 JSONCodec

type JSONCodec[T any] struct{}

JSONCodec 为任意值提供 JSON 编解码。

func (JSONCodec[T]) Marshal

func (JSONCodec[T]) Marshal(value T) ([]byte, error)

func (JSONCodec[T]) Name

func (JSONCodec[T]) Name() string

func (JSONCodec[T]) Unmarshal

func (JSONCodec[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 StoreKey

type StoreKey string

StoreKey 是不可变的 typed store 键值对象。

func MustStoreKey

func MustStoreKey(key string) StoreKey

MustStoreKey 创建 store 键,输入非法时 panic。

func NewStoreKey

func NewStoreKey(key string) (StoreKey, error)

NewStoreKey 创建经过校验的 store 键。

func (StoreKey) String

func (k StoreKey) String() string

String 返回原始 Redis 键字符串。

type StringCodec

type StringCodec struct{}

StringCodec 用于存储原始字符串。

func (StringCodec) Marshal

func (StringCodec) Marshal(value string) ([]byte, error)

func (StringCodec) Name

func (StringCodec) Name() string

func (StringCodec) Unmarshal

func (StringCodec) Unmarshal(payload []byte) (string, error)

type ValueCodec

type ValueCodec[T any] interface {
	Marshal(value T) ([]byte, error)
	Unmarshal(payload []byte) (T, error)
	Name() string
}

ValueCodec 负责 typed value 的编解码。

type ValueEnvelope

type ValueEnvelope struct {
	Payload    []byte
	TTL        int64
	Encoding   string
	Compressed bool
}

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]) Exists

func (s *ValueStore[T]) Exists(ctx context.Context, key StoreKey) (bool, error)

Exists 返回键是否存在。

func (*ValueStore[T]) Get

func (s *ValueStore[T]) Get(ctx context.Context, key StoreKey) (T, bool, error)

Get 读取并解码一个 typed value。

func (*ValueStore[T]) Set

func (s *ValueStore[T]) Set(ctx context.Context, key StoreKey, value T, ttl time.Duration) error

Set 编码并写入一个 typed value。

func (*ValueStore[T]) SetIfAbsent

func (s *ValueStore[T]) SetIfAbsent(ctx context.Context, key StoreKey, value T, ttl time.Duration) (bool, error)

SetIfAbsent 仅在键不存在时写入 typed value。

Jump to

Keyboard shortcuts

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