cache: use badgerdb (#15)
This commit is contained in:
10
cache/put.go
vendored
10
cache/put.go
vendored
@@ -2,13 +2,17 @@ package cache
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xujiajun/nutsdb"
|
||||
"github.com/dgraph-io/badger/v3"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *Client) Put(bucket string, key string, val []byte, ttl time.Duration) error {
|
||||
if err := c.db.Update(func(tx *nutsdb.Tx) error {
|
||||
return tx.Put(bucket, []byte(key), val, uint32(ttl.Seconds()))
|
||||
if err := c.db.Update(func(txn *badger.Txn) error {
|
||||
e := badger.NewEntry([]byte(fmt.Sprintf("%s_%s", bucket, key)), val)
|
||||
if ttl > 0 {
|
||||
e = e.WithTTL(ttl)
|
||||
}
|
||||
return txn.SetEntry(e)
|
||||
}); err != nil {
|
||||
return fmt.Errorf("%v: %v; put: %w", bucket, key, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user