buntdb

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: AGPL-3.0 Imports: 11 Imported by: 14

Documentation

Index

Constants

View Source
const LSPDB = ".lsp.db"
View Source
const MEMORYDB = ":memory:"

Variables

View Source
var (
	ErrKeyExist       = errors.New("key exist")
	ErrNotInitialized = errors.New("not initialized")
	ErrRollback       = errors.New("rollback")
	ErrLockNotHold    = errors.New("lock not hold")
)

Functions

func AcfunLiveInfoKey

func AcfunLiveInfoKey(keys ...interface{}) string

func AcfunNotLiveKey

func AcfunNotLiveKey(keys ...interface{}) string

func AcfunUidFirstTimestampKey

func AcfunUidFirstTimestampKey(keys ...interface{}) string

func AcfunUserInfoKey

func AcfunUserInfoKey(keys ...interface{}) string

func BilibiliActiveTimestampKey

func BilibiliActiveTimestampKey(keys ...interface{}) string

func BilibiliCompactMarkKey

func BilibiliCompactMarkKey(keys ...interface{}) string

func BilibiliCurrentLiveKey

func BilibiliCurrentLiveKey(keys ...interface{}) string

func BilibiliCurrentNewsKey

func BilibiliCurrentNewsKey(keys ...interface{}) string

func BilibiliDynamicIdKey

func BilibiliDynamicIdKey(keys ...interface{}) string

func BilibiliGroupAtAllMarkKey

func BilibiliGroupAtAllMarkKey(keys ...interface{}) string

func BilibiliGroupConcernConfigKey

func BilibiliGroupConcernConfigKey(keys ...interface{}) string

func BilibiliGroupConcernStateKey

func BilibiliGroupConcernStateKey(keys ...interface{}) string

func BilibiliLastFreshKey

func BilibiliLastFreshKey(keys ...interface{}) string

func BilibiliNotLiveCountKey

func BilibiliNotLiveCountKey(keys ...interface{}) string

func BilibiliNotifyMsgKey

func BilibiliNotifyMsgKey(keys ...interface{}) string

func BilibiliUidFirstTimestampKey

func BilibiliUidFirstTimestampKey(keys ...interface{}) string

func BilibiliUserCookieInfoKey

func BilibiliUserCookieInfoKey(keys ...interface{}) string

func BilibiliUserInfoKey

func BilibiliUserInfoKey(keys ...interface{}) string

func BilibiliUserStatKey

func BilibiliUserStatKey(keys ...interface{}) string

func BilibliFreshKey

func BilibliFreshKey(keys ...interface{}) string

func BlockListKey

func BlockListKey(keys ...interface{}) string

func Close

func Close() error

Close 关闭buntdb,正常情况下框架会负责关闭

func CreatePatternIndex

func CreatePatternIndex(patternFunc KeyPatternFunc, suffix []interface{}, less ...func(a, b string) bool) error

func DDBotNoUpdateKey

func DDBotNoUpdateKey(keys ...interface{}) string

func DDBotReleaseKey

func DDBotReleaseKey(keys ...interface{}) string

func Delete

func Delete(key string, opt ...OptionFunc) (string, error)

Delete 删除key,并返回key上的值 支持 IgnoreNotFoundOpt

func DeleteInt64

func DeleteInt64(key string, opt ...OptionFunc) (int64, error)

DeleteInt64 删除key,解析key上的值到int64并返回 支持 IgnoreNotFoundOpt

func DouyuCurrentLiveKey

func DouyuCurrentLiveKey(keys ...interface{}) string

func DouyuFreshKey

func DouyuFreshKey(keys ...interface{}) string

func DouyuGroupAtAllMarkKey

func DouyuGroupAtAllMarkKey(keys ...interface{}) string

func DouyuGroupConcernConfigKey

func DouyuGroupConcernConfigKey(keys ...interface{}) string

func DouyuGroupConcernStateKey

func DouyuGroupConcernStateKey(keys ...interface{}) string

func Exist

func Exist(key string, opt ...OptionFunc) bool

Exist 查询key是否存在,key不存在或者发生任何错误时返回 false 支持 GetTTLOpt GetIgnoreExpireOpt

func ExpireOption

func ExpireOption(duration time.Duration) *buntdb.SetOptions

ExpireOption 是一个创建 buntdb.SetOptions 的函数糖,当直接操作底层buntdb的时候可以使用。 使用本package的时候请使用 SetExpireOpt

func Get

func Get(key string, opt ...OptionFunc) (string, error)

Get 通过key获取value 支持 GetIgnoreExpireOpt IgnoreNotFoundOpt GetTTLOpt

func GetClient

func GetClient() (*buntdb.DB, error)

GetClient 获取 buntdb.DB 对象,如果没有初始化会返回 ErrNotInitialized

func GetInt64

func GetInt64(key string, opt ...OptionFunc) (int64, error)

GetInt64 通过key获取value,并将value解析成int64 支持 GetIgnoreExpireOpt IgnoreNotFoundOpt GetTTLOpt 当设置了 IgnoreNotFoundOpt 时,key不存在时会直接返回0

func GetJson

func GetJson(key string, obj interface{}, opt ...OptionFunc) error

GetJson 获取key对应的value,并通过 json.Unmarshal 到obj上 支持 GetIgnoreExpireOpt IgnoreNotFoundOpt GetTTLOpt

func GlobalEnabledKey

func GlobalEnabledKey(keys ...interface{}) string

func GlobalSilenceKey

func GlobalSilenceKey(keys ...interface{}) string

func GroupEnabledKey

func GroupEnabledKey(keys ...interface{}) string

func GroupInvitedKey

func GroupInvitedKey(keys ...interface{}) string

func GroupInvitorKey

func GroupInvitorKey(keys ...interface{}) string

func GroupMessageImageKey

func GroupMessageImageKey(keys ...interface{}) string

func GroupMuteKey

func GroupMuteKey(keys ...interface{}) string

func GroupPermissionKey

func GroupPermissionKey(keys ...interface{}) string

func GroupSilenceKey

func GroupSilenceKey(keys ...interface{}) string

func HuyaCurrentLiveKey

func HuyaCurrentLiveKey(keys ...interface{}) string

func HuyaFreshKey

func HuyaFreshKey(keys ...interface{}) string

func HuyaGroupAtAllMarkKey

func HuyaGroupAtAllMarkKey(keys ...interface{}) string

func HuyaGroupConcernConfigKey

func HuyaGroupConcernConfigKey(keys ...interface{}) string

func HuyaGroupConcernStateKey

func HuyaGroupConcernStateKey(keys ...interface{}) string

func ImageCacheKey

func ImageCacheKey(keys ...interface{}) string

func IncInt64

func IncInt64(key string, value int64) (int64, error)

IncInt64 将key上的int64值加上 value 并保存,返回保存后的值。 如果key不存在,则会默认其为0,返回值为1 如果key上的value不是一个int64,则会返回错误

func InitBuntDB

func InitBuntDB(dbpath string) error

InitBuntDB 初始化buntdb,正常情况下框架会负责初始化

func IsNotFound

func IsNotFound(e error) bool

func IsRollback

func IsRollback(e error) bool

func Key

func Key(keys ...interface{}) string

func LoliconPoolStoreKey

func LoliconPoolStoreKey(keys ...interface{}) string

func ModeKey

func ModeKey() string

func MustGetClient

func MustGetClient() *buntdb.DB

MustGetClient 获取 buntdb.DB 对象,如果没有初始化会panic,在编写订阅组件时可以放心调用

func NamedKey

func NamedKey(name string, keys []interface{}) string

func NewFriendRequestKey

func NewFriendRequestKey(keys ...interface{}) string

func ParseConcernStateKeyWithInt64

func ParseConcernStateKeyWithInt64(key string) (groupCode int64, id int64, err error)

func ParseConcernStateKeyWithString

func ParseConcernStateKeyWithString(key string) (groupCode int64, id string, err error)

func PermissionKey

func PermissionKey(keys ...interface{}) string

func RCover

func RCover(f func() error) error

RCover 在一个只读事务中执行f,不同的是它不获取 buntdb.Tx ,而由 f 自己控制。 所有写操作会失败,或者回滚。

func RCoverTx

func RCoverTx(f func(tx *buntdb.Tx) error) error

RCoverTx 在一个只读事务中执行f。 所有写操作会失败或者回滚。

func RWCover

func RWCover(f func() error) error

RWCover 在一个可读可写事务中执行f,不同的是它不获取 buntdb.Tx ,而由 f 自己控制。 需要注意可写事务是唯一的,同一时间只会存在一个可写事务,所有耗时操作禁止放在可写事务中执行 在同一Goroutine中,可写事务可以嵌套

func RWCoverTx

func RWCoverTx(f func(tx *buntdb.Tx) error) error

RWCoverTx 在一个可读可写事务中执行f,注意f的返回值不一定是RWCoverTx的返回值 有可能f返回nil,但RWTxCover返回non-nil 可以忽略error,但不要简单地用f返回值替代RWTxCover返回值,ref: bilibili/MarkDynamicId 需要注意可写事务是唯一的,同一时间只会存在一个可写事务,所有耗时操作禁止放在可写事务中执行 在同一Goroutine中,可写事务可以嵌套

func RemoveByPrefixAndIndex

func RemoveByPrefixAndIndex(prefixKey []string, indexKey []string) ([]string, error)

RemoveByPrefixAndIndex 遍历每个index,如果一个key满足任意prefix,则删掉

func SeqNext

func SeqNext(key string) (int64, error)

SeqNext 将key上的int64值加上1并保存,返回保存后的值。 如果key不存在,则会默认其为0,返回值为1 等价于 IncInt64(key, 1)

func Set

func Set(key, value string, opt ...OptionFunc) error

Set 通过key设置value 支持 SetExpireOpt SetKeepLastExpireOpt SetNoOverWriteOpt SetGetIsOverwriteOpt SetGetPreviousValueStringOpt SetGetPreviousValueInt64Opt SetGetPreviousValueJsonObjectOpt

func SetInt64

func SetInt64(key string, value int64, opt ...OptionFunc) error

SetInt64 通过key设置int64格式的value 支持 SetExpireOpt SetKeepLastExpireOpt SetNoOverWriteOpt SetGetIsOverwriteOpt SetGetPreviousValueStringOpt SetGetPreviousValueInt64Opt SetGetPreviousValueJsonObjectOpt

func SetJson

func SetJson(key string, obj interface{}, opt ...OptionFunc) error

SetJson 将obj通过 json.Marshal 转成json字符串,并设置到key上。 支持 SetExpireOpt SetKeepLastExpireOpt SetNoOverWriteOpt SetGetIsOverwriteOpt SetGetPreviousValueStringOpt SetGetPreviousValueInt64Opt SetGetPreviousValueJsonObjectOpt

func VersionKey

func VersionKey(keys ...interface{}) string

func WeiboMarkMblogIdKey

func WeiboMarkMblogIdKey(keys ...interface{}) string

func WeiboNewsInfoKey

func WeiboNewsInfoKey(keys ...interface{}) string

func WeiboUserInfoKey

func WeiboUserInfoKey(keys ...interface{}) string

func YoutubeFreshKey

func YoutubeFreshKey(keys ...interface{}) string

func YoutubeGroupAtAllMarkKey

func YoutubeGroupAtAllMarkKey(keys ...interface{}) string

func YoutubeGroupConcernConfigKey

func YoutubeGroupConcernConfigKey(keys ...interface{}) string

func YoutubeGroupConcernStateKey

func YoutubeGroupConcernStateKey(keys ...interface{}) string

func YoutubeInfoKey

func YoutubeInfoKey(keys ...interface{}) string

func YoutubeUserInfoKey

func YoutubeUserInfoKey(keys ...interface{}) string

func YoutubeVideoKey

func YoutubeVideoKey(keys ...interface{}) string

Types

type KeyPatternFunc

type KeyPatternFunc func(...interface{}) string

type OptionFunc

type OptionFunc func(o *option)

func GetIgnoreExpireOpt

func GetIgnoreExpireOpt() OptionFunc

GetIgnoreExpireOpt Get配置,忽略key的过期时间,如果key曾经设置过但已经过期,依然可以获取到

func GetTTLOpt

func GetTTLOpt(ttl *time.Duration) OptionFunc

GetTTLOpt 获取key上的ttl

func IgnoreNotFoundOpt

func IgnoreNotFoundOpt() OptionFunc

IgnoreNotFoundOpt 获取值时不返回 buntdb.ErrNotFound ,而是返回nil

func SetExpireOpt

func SetExpireOpt(expire time.Duration) OptionFunc

SetExpireOpt 设置set时的过期时间 该设置与 SetKeepLastExpireOpt 同时设置时,本设置会生效

func SetGetIsOverwriteOpt

func SetGetIsOverwriteOpt(isOverWrite *bool) OptionFunc

SetGetIsOverwriteOpt Set配置,获取此次set是否将覆盖一个旧值,可以与 SetNoOverWriteOpt 同时设置

func SetGetPreviousValueInt64Opt

func SetGetPreviousValueInt64Opt(previous *int64) OptionFunc

SetGetPreviousValueInt64Opt Set配置,将key的上一个值解析到int64并放到previous中

func SetGetPreviousValueJsonObjectOpt

func SetGetPreviousValueJsonObjectOpt(previous interface{}) OptionFunc

SetGetPreviousValueJsonObjectOpt Set配置,将key的上一个值用json解析并放到previous中

func SetGetPreviousValueStringOpt

func SetGetPreviousValueStringOpt(previous *string) OptionFunc

SetGetPreviousValueStringOpt Set配置,存储key上一个值到previous中

func SetKeepLastExpireOpt

func SetKeepLastExpireOpt() OptionFunc

SetKeepLastExpireOpt 设置set时保留上次的过期时间 该设置与 SetKeepLastExpireOpt 同时设置时, SetExpireOpt 设置会生效

func SetNoOverWriteOpt

func SetNoOverWriteOpt() OptionFunc

SetNoOverWriteOpt Set配置,当key已经存在时不进行覆盖,而是返回 ErrRollback

type ShortCut

type ShortCut struct{}

ShortCut 包含了许多数据库的读写helper,只需嵌入即可使用,如果不想嵌入,也可以通过包名调用

func (*ShortCut) CreatePatternIndex

func (s *ShortCut) CreatePatternIndex(patternFunc KeyPatternFunc, suffix []interface{}, less ...func(a, b string) bool) error

func (*ShortCut) Delete

func (s *ShortCut) Delete(key string, opt ...OptionFunc) (string, error)

Delete 删除key,并返回key上的值 支持 IgnoreNotFoundOpt

func (*ShortCut) DeleteInt64

func (s *ShortCut) DeleteInt64(key string, opt ...OptionFunc) (int64, error)

DeleteInt64 删除key,解析key上的值到int64并返回 支持 IgnoreNotFoundOpt

func (*ShortCut) Exist

func (s *ShortCut) Exist(key string, opt ...OptionFunc) bool

Exist 查询key是否存在,key不存在或者发生任何错误时返回 false 支持 GetTTLOpt GetIgnoreExpireOpt

func (*ShortCut) Get

func (s *ShortCut) Get(key string, opt ...OptionFunc) (string, error)

Get 通过key获取value 支持 GetIgnoreExpireOpt IgnoreNotFoundOpt GetTTLOpt

func (*ShortCut) GetInt64

func (s *ShortCut) GetInt64(key string, opt ...OptionFunc) (int64, error)

GetInt64 通过key获取value,并将value解析成int64 支持 GetIgnoreExpireOpt IgnoreNotFoundOpt GetTTLOpt 当设置了 IgnoreNotFoundOpt 时,key不存在时会直接返回0,不会返回错误

func (*ShortCut) GetJson

func (s *ShortCut) GetJson(key string, obj interface{}, opt ...OptionFunc) error

GetJson 获取key对应的value,并通过 json.Unmarshal 到obj上 支持 GetIgnoreExpireOpt IgnoreNotFoundOpt GetTTLOpt

func (*ShortCut) IncInt64

func (s *ShortCut) IncInt64(key string, value int64) (int64, error)

IncInt64 将key上的int64值加上 value 并保存,返回保存后的值。 如果key不存在,则会默认其为0,返回值为1 如果key上的value不是一个int64,则会返回错误

func (*ShortCut) RCover

func (*ShortCut) RCover(f func() error) error

RCover 在一个只读事务中执行f,不同的是它不获取 buntdb.Tx ,而由 f 自己控制。 所有写操作会失败,或者回滚。

func (*ShortCut) RCoverTx

func (*ShortCut) RCoverTx(f func(tx *buntdb.Tx) error) error

RCoverTx 在一个只读事务中执行f。 所有写操作会失败或者回滚。

func (*ShortCut) RWCover

func (*ShortCut) RWCover(f func() error) error

RWCover 在一个可读可写事务中执行f,不同的是它不获取 buntdb.Tx ,而由 f 自己控制。 需要注意可写事务是唯一的,同一时间只会存在一个可写事务,所有耗时操作禁止放在可写事务中执行 在同一Goroutine中,可写事务可以嵌套

func (*ShortCut) RWCoverTx

func (*ShortCut) RWCoverTx(f func(tx *buntdb.Tx) error) error

RWCoverTx 在一个可读可写事务中执行f,注意f的返回值不一定是RWCoverTx的返回值 有可能f返回nil,但RWTxCover返回non-nil 可以忽略error,但不要简单地用f返回值替代RWTxCover返回值,ref: bilibili/MarkDynamicId 需要注意可写事务是唯一的,同一时间只会存在一个可写事务,所有耗时操作禁止放在可写事务中执行 在同一Goroutine中,可写事务可以嵌套

func (*ShortCut) SeqNext

func (s *ShortCut) SeqNext(key string) (int64, error)

SeqNext 将key上的int64值加上1并保存,返回保存后的值。 如果key不存在,则会默认其为0,返回值为1 等价于 s.IncInt64(key, 1)

func (*ShortCut) Set

func (s *ShortCut) Set(key, value string, opt ...OptionFunc) error

Set 通过key设置value 支持 SetExpireOpt SetKeepLastExpireOpt SetNoOverWriteOpt SetGetIsOverwriteOpt SetGetPreviousValueStringOpt SetGetPreviousValueInt64Opt SetGetPreviousValueJsonObjectOpt

func (*ShortCut) SetInt64

func (s *ShortCut) SetInt64(key string, value int64, opt ...OptionFunc) error

SetInt64 通过key设置int64格式的value 支持 SetExpireOpt SetKeepLastExpireOpt SetNoOverWriteOpt SetGetIsOverwriteOpt SetGetPreviousValueStringOpt SetGetPreviousValueInt64Opt SetGetPreviousValueJsonObjectOpt

func (*ShortCut) SetJson

func (s *ShortCut) SetJson(key string, obj interface{}, opt ...OptionFunc) error

SetJson 将obj通过 json.Marshal 转成json字符串,并设置到key上。 支持 SetExpireOpt SetKeepLastExpireOpt SetNoOverWriteOpt SetGetIsOverwriteOpt SetGetPreviousValueStringOpt SetGetPreviousValueInt64Opt SetGetPreviousValueJsonObjectOpt

Jump to

Keyboard shortcuts

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