dets

package module
v0.0.0-...-4f42c6d Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 7 Imported by: 3

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()
}

函数一览

PutDel函数统一使用,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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del

func Del(key []byte)

Del 删除键值

func Get

func Get(key []byte) []byte

Get returns the value associated with the key as a byte slice.

func GetBool

func GetBool(key []byte) bool

GetBool returns the value associated with the key as a boolean.

func GetDuration

func GetDuration(key []byte) time.Duration

GetDuration returns the value associated with the key as a duration.

func GetFloat64

func GetFloat64(key []byte) float64

GetFloat64 returns the value associated with the key as a float64.

func GetInt

func GetInt(key []byte) int

GetInt returns the value associated with the key as an integer.

func GetInt32

func GetInt32(key []byte) int32

GetInt32 returns the value associated with the key as an integer.

func GetInt64

func GetInt64(key []byte) int64

GetInt64 returns the value associated with the key as an integer.

func GetIntSlice

func GetIntSlice(key []byte) []int

GetIntSlice returns the value associated with the key as a slice of int values.

func GetString

func GetString(key []byte) string

GetString returns the value associated with the key as a string.

func GetStringMap

func GetStringMap(key []byte) map[string]string

GetStringMap returns the value associated with the key as a map of strings.

func GetStringMapStringSlice

func GetStringMapStringSlice(key []byte) map[string][]string

GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings.

func GetStringSlice

func GetStringSlice(key []byte) []string

GetStringSlice returns the value associated with the key as a slice of strings.

func GetTime

func GetTime(key []byte) time.Time

GetTime 需要注意,使用time.Now()返回的time.Time包含Wall Clock和Monotonic Clock。 在Marshal之后,Monotonic Clock部分会被丢弃,所以在Unmarshal之后和原来的并不完全相同。

在一般业务场景下,存储时间戳的精度其实就足够了。

func GetUint

func GetUint(key []byte) uint

GetUint returns the value associated with the key as an unsigned integer.

func GetUint32

func GetUint32(key []byte) uint32

GetUint32 returns the value associated with the key as an unsigned integer.

func GetUint64

func GetUint64(key []byte) uint64

GetUint64 returns the value associated with the key as an unsigned integer.

func Put

func Put(key []byte, value interface{}, ttl ...time.Duration)

Put 设置键值。你可以指定一个超时时间。

func SetDB

func SetDB(d *badger.DB, l ...LogInterface)

SetDB 用以和dgraph-io/badge配合使用

func Start

func Start(path string, l ...LogInterface)

Start 启动数据库

func Stop

func Stop()

Stop 关闭数据库并保存数据

Types

type LogInterface

type LogInterface interface {
	Error(msg string, args ...any)
}

Jump to

Keyboard shortcuts

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