Added simple config command

This commit is contained in:
tidwall 2021-01-17 08:27:23 -07:00
parent 0205c889f6
commit aef242afd1
1 changed files with 11 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"log" "log"
"strings" "strings"
"sync" "sync"
"time"
"github.com/tidwall/redcon" "github.com/tidwall/redcon"
) )
@ -15,7 +16,8 @@ func main() {
var items = make(map[string][]byte) var items = make(map[string][]byte)
var ps redcon.PubSub var ps redcon.PubSub
go log.Printf("started server at %s", addr) go log.Printf("started server at %s", addr)
err := redcon.ListenAndServe(addr,
s := redcon.NewServer(addr,
func(conn redcon.Conn, cmd redcon.Command) { func(conn redcon.Conn, cmd redcon.Command) {
switch strings.ToLower(string(cmd.Args[0])) { switch strings.ToLower(string(cmd.Args[0])) {
default: default:
@ -95,6 +97,12 @@ func main() {
} else { } else {
conn.WriteInt(1) conn.WriteInt(1)
} }
case "config":
// This simple (blank) response is only here to allow for the
// redis-benchmark command to work with this example.
conn.WriteArray(2)
conn.WriteBulk(cmd.Args[2])
conn.WriteBulkString("")
} }
}, },
func(conn redcon.Conn) bool { func(conn redcon.Conn) bool {
@ -107,6 +115,8 @@ func main() {
// log.Printf("closed: %s, err: %v", conn.RemoteAddr(), err) // log.Printf("closed: %s, err: %v", conn.RemoteAddr(), err)
}, },
) )
s.SetIdleClose(time.Second * 5)
err := s.ListenAndServe()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }