forked from tekton/ccdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.go
38 lines (30 loc) · 731 Bytes
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"errors"
badger "github.com/dgraph-io/badger/v4"
"github.com/rs/zerolog/log"
"github.com/tidwall/redcon"
)
func get(db *badger.DB, _ redcon.Conn, cmd redcon.Command) (any, error) {
if len(cmd.Args) != 2 {
return nil, errors.New("ERR wrong number of arguments for 'GET' command")
}
log.Debug().Str("key", string(cmd.Args[1])).Msg("get")
var bdgrVal []byte
if err := db.View(func(txn *badger.Txn) error {
item, gErr := txn.Get(cmd.Args[1])
if gErr != nil {
return gErr
}
if err := item.Value(func(val []byte) error {
bdgrVal = append([]byte{}, val...)
return nil
}); err != nil {
return err
}
return nil
}); err != nil {
return nil, nil
}
return bdgrVal, nil
}