badgerdb

package
v0.0.8-20250724 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

badgerdb包:基于BadgerDB的高性能本地缓存实现 提供键值存储、哈希表操作、队列操作和事务支持

BadgerDB是一个高性能的LSM树Key-Value存储引擎,专为SSD优化设计 本包实现了Cache接口,提供统一的缓存操作API

主要特性: - 高性能读写操作,基于LSM树结构 - 支持TTL过期机制 - 队列操作(FIFO/LIFO) - 哈希表操作(通过复合键实现) - 事务支持(读写事务) - 线程安全的并发访问 - 自动垃圾回收和压缩 - 本地文件存储,无需外部依赖

使用场景: - 本地高性能缓存 - 嵌入式应用存储 - 单机应用的持久化缓存

作者: gophertool

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBadgerStore

func NewBadgerStore(config config.Cache) (_interface.Cache, error)

NewBadgerStore 创建BadgerDB缓存实例的工厂函数 参数:

config - 缓存配置

返回值:

Cache - 缓存接口实例
error - 创建错误

Types

type BadgerDb

type BadgerDb struct {
	// contains filtered or unexported fields
}

BadgerDb BadgerDB缓存实现结构体

func (*BadgerDb) BeginTx

func (b *BadgerDb) BeginTx() (_interface.Tx, error)

func (*BadgerDb) Close

func (b *BadgerDb) Close()

func (*BadgerDb) Delete

func (b *BadgerDb) Delete(key string) error

func (*BadgerDb) Exists

func (b *BadgerDb) Exists(key string) (bool, error)

func (*BadgerDb) Expire

func (b *BadgerDb) Expire(key string, ttl time.Duration) error

func (*BadgerDb) Get

func (b *BadgerDb) Get(key string) (string, error)

Get 获取指定key的值 参数:

key - 键名

返回值:

string - 键对应的值
error - 操作错误,键不存在时返回ErrKeyNotFound

func (*BadgerDb) HDel

func (b *BadgerDb) HDel(key, field string) error

func (*BadgerDb) HGet

func (b *BadgerDb) HGet(key, field string) (string, error)

func (*BadgerDb) HGetAll

func (b *BadgerDb) HGetAll(key string) (map[string]string, error)

func (*BadgerDb) HSet

func (b *BadgerDb) HSet(key, field, value string, ttl time.Duration) error

func (*BadgerDb) LPop

func (b *BadgerDb) LPop(key string) (string, error)

LPop 弹出列表头部元素 参数:

key - 列表键名

返回值:

string - 弹出的元素值
error - 操作错误

func (*BadgerDb) LPush

func (b *BadgerDb) LPush(key string, value string) error

LPush 将元素插入到列表头部 参数:

key - 列表键名
value - 要插入的值

返回值:

error - 操作错误

func (*BadgerDb) Len

func (b *BadgerDb) Len(key string) (int64, error)

Len 获取列表长度

func (*BadgerDb) Pop

func (b *BadgerDb) Pop(key string) (string, error)

Pop 移除并返回列表最后一个元素

func (*BadgerDb) PopAll

func (b *BadgerDb) PopAll(key string) ([]string, error)

PopAll 取出并清空整个列表

func (*BadgerDb) Push

func (b *BadgerDb) Push(key string, value string) error

Push 添加元素到列表尾部

func (*BadgerDb) RPop

func (b *BadgerDb) RPop(key string) (string, error)

RPop 弹出列表尾部元素

func (*BadgerDb) RPush

func (b *BadgerDb) RPush(key string, value string) error

RPush 将元素插入到列表尾部 参数:

key - 列表键名
value - 要插入的值

返回值:

error - 操作错误

func (*BadgerDb) Set

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

Jump to

Keyboard shortcuts

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