forked from tekton/ccdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec.go
38 lines (30 loc) · 810 Bytes
/
exec.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 (
"strings"
badger "github.com/dgraph-io/badger/v4"
"github.com/rs/zerolog/log"
"github.com/tidwall/redcon"
)
func exec(db *badger.DB, conn redcon.Conn, cmd redcon.Command) (any, error) {
log.Debug().Msg("exec")
mu.Lock()
defer mu.Unlock()
if len(connections[conn.RemoteAddr()].Commands) == 0 {
conn.WriteNull()
return nil, nil
}
responses := []any{}
for _, c := range connections[conn.RemoteAddr()].Commands {
cmdStr := strings.ToLower(string(c.Args[0]))
if selectedCmd, ok := commands[cmdStr]; ok {
res, err := selectedCmd(db, conn, c)
if err != nil {
return nil, err
}
responses = append(responses, res)
}
}
connections[conn.RemoteAddr()].Multi = false
connections[conn.RemoteAddr()].Commands = []redcon.Command{}
return responses, nil
}