feat(store): add FileInfoStore
This commit is contained in:
parent
834c577a71
commit
c78692df52
4 changed files with 143 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue