modulepackage
0.0.0-20241008030144-8dd164c22481
Repository: https://github.com/cutereimu/dets.git
Documentation: pkg.go.dev
# README
dets
基于 dgraph-io/badger 做的内嵌式key-value型数据库的接口封装。
因为仅仅是接口封装,所以对于同一个key,不支持并发。想要支持并发,请直接使用 dgraph-io/badger
安装
go get github.com/CuteReimu/dets
使用方法举例
package main
import (
"fmt"
"github.com/CuteReimu/dets"
)
func main() {
dets.Start("temp")
key := []byte("aaa")
dets.Put(key, "vvv")
s := dets.GetString(key)
dets.Del(key)
fmt.Println(s)
dets.Stop()
}
函数一览
Put
和Del
函数统一使用,Get
用了不同的函数名
支持的value类型 | 对应Get 函数名 |
---|---|
[]byte | Get |
string | GetString |
bool | GetBool |
int | GetInt |
int32 | GetInt32 |
int64 | GetInt64 |
uint | GetUint |
uint32 | GetUint32 |
uint64 | GetUint64 |
float64 | GetFloat64 |
time.Time | GetTime |
time.Duration | GetDuration |
[]int | GetIntSlice |
[]string | GetStringSlice |
map[string]string | GetStringMap |
map[string][]string | GetStringMapStringSlice |
# Functions
Del 删除键值.
Get returns the value associated with the key as a byte slice.
GetBool returns the value associated with the key as a boolean.
GetDuration returns the value associated with the key as a duration.
GetFloat64 returns the value associated with the key as a float64.
GetInt returns the value associated with the key as an integer.
GetInt32 returns the value associated with the key as an integer.
GetInt64 returns the value associated with the key as an integer.
GetIntSlice returns the value associated with the key as a slice of int values.
GetString returns the value associated with the key as a string.
GetStringMap returns the value associated with the key as a map of strings.
GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.
GetStringSlice returns the value associated with the key as a slice of strings.
GetTime 需要注意,使用time.Now()返回的time.Time包含Wall Clock和Monotonic Clock。 在Marshal之后,Monotonic Clock部分会被丢弃,所以在Unmarshal之后和原来的并不完全相同。
在一般业务场景下,存储时间戳的精度其实就足够了。.
GetUint returns the value associated with the key as an unsigned integer.
GetUint32 returns the value associated with the key as an unsigned integer.
GetUint64 returns the value associated with the key as an unsigned integer.
Put 设置键值。你可以指定一个超时时间。.
SetDB 用以和dgraph-io/badge配合使用.
Start 启动数据库.
Stop 关闭数据库并保存数据.
# Interfaces
No description provided by the author