kvstore

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 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")
)

Functions

func Close

func Close()

Close 关闭数据库连接并停止后台任务

func Delete

func Delete(key string) error

Delete 删除键

func Exists

func Exists(key string) bool

Exists 检查键是否存在

func Get

func Get(key string) (string, error)

Get 获取字符串值

func GetBytes

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

GetBytes 获取原始字节数组

func GetInt64

func GetInt64(key string) (int64, error)

GetInt64 获取 int64 类型的计数器值

func GetManyInt64

func GetManyInt64(keys []string) (map[string]int64, error)

GetManyInt64 批量获取 int64 类型的计数器值 适用于列表页展示(如批量获取一页帖子的浏览量) 返回结果 map,key 为传入的 key,value 为计数值(不存在的 key 默认为 0)

func GetOnlineUserCount

func GetOnlineUserCount() (int, error)

GetOnlineUserCount 获取当前在线用户数 通过遍历匹配前缀且未过期的 Key 数量来实现

func Increment

func Increment(key string, delta int64) (int64, error)

Increment 增加(或减少)计数器的值并返回新值 适用于统计在线人数 (delta 为 1 或 -1) 或帖子浏览量

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 SetUserOnline

func SetUserOnline(userId string) error

SetUserOnline 标记用户在线,设置 3 分钟 TTL 每次用户活动时调用此方法续期

Types

This section is empty.

Jump to

Keyboard shortcuts

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