tidwall / redcon

Redis compatible server framework for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do you accept port 6380 and socket at the same time?

hiqsociety opened this issue · comments

with reference to this:
#21

How can it be done? I know one or the other but not both.

Thank you for redcon. It's truly amazing.

Your best bet is to listen on both sockets in different goroutines first and share the same handler

package main

import (
	"os"

	"github.com/tidwall/redcon"
)

func main() {
	go func() {
		panic(redcon.ListenAndServeNetwork("tcp", ":6380",
			handler, accept, close))
	}()
	go func() {
		os.RemoveAll("my-unix-path")
		panic(redcon.ListenAndServeNetwork("unix", "my-unix-path",
			handler, accept, close))
	}()
	println("* Serving on port 6380 and on socket my-unix-path")
	select {}
}

func handler(conn redcon.Conn, cmd redcon.Command) {
}
func accept(conn redcon.Conn) bool {

	return true
}
func close(conn redcon.Conn, err error) {

}

I'm closing this issue for now. Please feel free to reopen if you have further questions.