From eb2a6830c594be6e97f8217daffc7e37f0d27ecf Mon Sep 17 00:00:00 2001 From: ringsaturn Date: Sat, 2 Sep 2023 12:03:17 +0800 Subject: [PATCH] feat: custom Redis server addr (#97) --- internal/handler/redis_server.go | 4 ++-- internal/handler/redis_server_call_by_client_test.go | 2 +- main.go | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/handler/redis_server.go b/internal/handler/redis_server.go index c53f1e7..2943a83 100644 --- a/internal/handler/redis_server.go +++ b/internal/handler/redis_server.go @@ -79,8 +79,8 @@ func RedisHandler(conn redcon.Conn, cmd redcon.Command) { } } -func StartRedisServer() error { - err := redcon.ListenAndServe(":6380", +func StartRedisServer(addr string) error { + err := redcon.ListenAndServe(addr, RedisHandler, func(conn redcon.Conn) bool { return true }, func(conn redcon.Conn, err error) {}, diff --git a/internal/handler/redis_server_call_by_client_test.go b/internal/handler/redis_server_call_by_client_test.go index 3dee0de..f00065e 100644 --- a/internal/handler/redis_server_call_by_client_test.go +++ b/internal/handler/redis_server_call_by_client_test.go @@ -26,7 +26,7 @@ var ( func mustStartServer() { redisServerOnce.Do(func() { - go func() { _ = handler.StartRedisServer() }() + go func() { _ = handler.StartRedisServer(":6380") }() time.Sleep(100 * time.Millisecond) }) } diff --git a/main.go b/main.go index 842ead7..9816d0a 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ func main() { finderType := flag.Int("type", 0, "which finder to use Polygon(0) or Fuzzy(1)") dataPath := flag.String("path", "", "custom data") httpAddr := flag.String("http-addr", "localhost:8080", "HTTP Host&Port") + redisAddr := flag.String("redis-addr", "localhost:6380", "Redis Server Host&Port") prometheusHostPorts := flag.String("prometheus-host-port", "localhost:8090", "Prometheus Host&Port") prometheusPath := flag.String("prometheus-path", "/hertz", "Prometheus Path") prometheusEnableGoCollector := flag.Bool("prometheus-enable-go-coll", true, "Enable Go Collector") @@ -84,7 +85,7 @@ func main() { g.Go(h.Run) - g.Go(handler.StartRedisServer) + g.Go(func() error { return handler.StartRedisServer(*redisAddr) }) panic(g.Wait()) }