diff --git a/cmd/redka/main.go b/cmd/redka/main.go index ff866ea..d434aa9 100644 --- a/cmd/redka/main.go +++ b/cmd/redka/main.go @@ -44,7 +44,7 @@ pragma foreign_keys = on;` type Config struct { Host string Port string - FIFO string + Sock string // unix socket Path string Verbose bool } @@ -63,7 +63,7 @@ func init() { } flag.StringVar(&config.Host, "h", "localhost", "server host") flag.StringVar(&config.Port, "p", "6379", "server port") - flag.StringVar(&config.FIFO, "F", "", "server FIFO") + flag.StringVar(&config.Sock, "s", "", "server socket (overrides host and port)") flag.BoolVar(&config.Verbose, "v", false, "verbose logging") // Register an SQLite driver with custom pragmas. @@ -122,13 +122,12 @@ func main() { slog.Info("data source", "path", config.Path) // Start the server. - - var srv *server.Server - if config.FIFO == "" { - srv = server.New("tcp", config.Addr(), db) - } else { - srv = server.New("unix", config.FIFO, db) - } + var srv *server.Server + if config.Sock != "" { + srv = server.New("unix", config.Sock, db) + } else { + srv = server.New("tcp", config.Addr(), db) + } srv.Start() // Wait for a shutdown signal. diff --git a/docs/usage-standalone.md b/docs/usage-standalone.md index 07f2752..378e01b 100644 --- a/docs/usage-standalone.md +++ b/docs/usage-standalone.md @@ -3,7 +3,7 @@ Redka server is a single-file binary. After [downloading and unpacking](install-standalone.md) the release asset, run it as follows: ``` -redka [-h host] [-p port] [db-path] +redka [-h host] [-p port] [-s unix-socket] [db-path] ``` For example: @@ -12,9 +12,10 @@ For example: ./redka ./redka data.db ./redka -h 0.0.0.0 -p 6379 data.db +./redka -s /tmp/redka.sock data.db ``` -Server defaults are host `localhost`, port `6379` and empty DB path. +Server defaults are host `localhost`, port `6379` and empty DB path. The unix socket path, if given, overrides the host/port arguments. Running without a DB path creates an in-memory database. The data is not persisted in this case, and will be gone when the server is stopped. diff --git a/internal/server/server.go b/internal/server/server.go index 3187a36..5d99f90 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -32,8 +32,8 @@ func New(net string, addr string, db *redka.DB) *Server { slog.Debug("close connection", "client", conn.RemoteAddr()) } } - return &Server{ - net: net, + return &Server{ + net: net, addr: addr, srv: redcon.NewServerNetwork(net, addr, handler, accept, closed), db: db,