kvstore

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotFound 键不存在
	ErrNotFound = errors.New("kvstore: key not found")
	// ErrInvalidKey key 为空或不合法
	ErrInvalidKey = errors.New("kvstore: invalid key")
	// ErrClosed 表示 kvstore 已关闭,应用生命周期内不应再次连接。
	ErrClosed = errors.New("kvstore: closed")
)

Functions

func Close

func Close()

Close 关闭当前已打开的 KV 连接;未连接时不做任何操作。

func Get

func Get(key string) (string, error)

Get 获取字符串值。

func GetBytes

func GetBytes(key string) ([]byte, error)

GetBytes 获取原始字节数组。

func Set

func Set(key string, value string, ttl time.Duration) error

Set 存储字符串。

func SetBytes

func SetBytes(key string, value []byte, ttl time.Duration) error

SetBytes 存储字节数组。

func UpdateBytes added in v0.2.14

func UpdateBytes(key string, ttl time.Duration, updater func(current []byte, exists bool) (UpdateAction, []byte, error)) error

UpdateBytes 在单个 Badger 事务内完成一个 key 的读改写。 updater 可能因事务冲突被重试,调用方应只基于 current/exists 计算返回值,避免在回调里执行外部副作用。

Types

type UpdateAction added in v0.2.14

type UpdateAction int

UpdateAction 表示 UpdateBytes 回调希望对当前 key 执行的操作。

const (
	// UpdateKeep 保持当前值不变。
	UpdateKeep UpdateAction = iota
	// UpdateSet 写入回调返回的新值。
	UpdateSet
)

Jump to

Keyboard shortcuts

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