feat(store): add FileInfoStore

This commit is contained in:
hexxa 2021-08-11 15:25:23 +08:00 committed by Hexxa
parent 834c577a71
commit c78692df52
4 changed files with 143 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package boltdbpvd
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
@ -154,6 +155,25 @@ func (bp *BoltPvd) ListBoolsIn(ns string) (map[string]bool, error) {
return list, err
}
func (bp *BoltPvd) ListBoolsByPrefixIn(prefix, ns string) (map[string]bool, error) {
results := map[string]bool{}
err := bp.db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(ns)).Cursor()
if b == nil {
return ErrBucketNotFound
}
prefixBytes := []byte(prefix)
for k, _ := b.Seek(prefixBytes); k != nil && bytes.HasPrefix(k, prefixBytes); k, _ = b.Next() {
results[string(k)] = true
}
return nil
})
return results, err
}
func (bp *BoltPvd) GetInt(key string) (int, bool) {
x, ok := bp.GetInt64(key)
return int(x), ok

View file

@ -17,6 +17,7 @@ type IKVStore interface {
DelBoolIn(ns, key string) error
ListBools() (map[string]bool, error)
ListBoolsIn(ns string) (map[string]bool, error)
ListBoolsByPrefixIn(prefix, ns string) (map[string]bool, error)
GetInt(key string) (int, bool)
SetInt(key string, val int) error
DelInt(key string) error