Support unix domain sockets in redis clients, too.

This commit is contained in:
Sascha L. Teichmann 2017-03-05 14:38:30 +01:00
parent ba2dd15280
commit e68e762322
4 changed files with 30 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"strings"
"bitbucket.org/s_l_teichmann/mtsatellite/common" "bitbucket.org/s_l_teichmann/mtsatellite/common"
) )
@ -71,7 +72,12 @@ func main() {
if !skipBaseLevel { if !skipBaseLevel {
td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0) td := common.Clamp32f(float32(transparentDim/100.0), 0.0, 1.0)
address := fmt.Sprintf("%s:%d", host, port) var address string
if strings.ContainsRune(host, '/') {
address = host
} else {
address = fmt.Sprintf("%s:%d", host, port)
}
if err := createBaseLevel( if err := createBaseLevel(
address, address,
xMin, yMin, zMin, xMax, yMax, zMax, xMin, yMin, zMin, xMax, yMax, zMax,

View File

@ -11,6 +11,7 @@ import (
"log" "log"
"os" "os"
"runtime/pprof" "runtime/pprof"
"strings"
"bitbucket.org/s_l_teichmann/mtsatellite/common" "bitbucket.org/s_l_teichmann/mtsatellite/common"
) )
@ -84,11 +85,16 @@ func main() {
colors.TransparentDim = common.Clamp32f( colors.TransparentDim = common.Clamp32f(
float32(transparentDim/100.0), 0.0, 100.0) float32(transparentDim/100.0), 0.0, 100.0)
address := fmt.Sprintf("%s:%d", host, port) var proto, address string
if strings.ContainsRune(host, '/') {
proto, address = "unix", host
} else {
proto, address = "tcp", fmt.Sprintf("%s:%d", host, port)
}
var client *common.RedisClient var client *common.RedisClient
if client, err = common.NewRedisClient("tcp", address); err != nil { if client, err = common.NewRedisClient(proto, address); err != nil {
log.Fatalf("Cannot connect to '%s': %s", address, err) log.Fatalf("Cannot connect to '%s': %s", address, err)
} }
defer client.Close() defer client.Close()

View File

@ -10,6 +10,7 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"strings"
"bitbucket.org/s_l_teichmann/mtsatellite/common" "bitbucket.org/s_l_teichmann/mtsatellite/common"
@ -113,7 +114,12 @@ func main() {
} }
colors.TransparentDim = common.Clamp32f( colors.TransparentDim = common.Clamp32f(
float32(transparentDim/100.0), 0.0, 100.0) float32(transparentDim/100.0), 0.0, 100.0)
redisAddress := fmt.Sprintf("%s:%d", redisHost, redisPort) var redisAddress string
if strings.ContainsRune(redisHost, '/') {
redisAddress = redisHost
} else {
redisAddress = fmt.Sprintf("%s:%d", redisHost, redisPort)
}
var allowedUpdateIps []net.IP var allowedUpdateIps []net.IP
if allowedUpdateIps, err = ipsFromHosts(updateHosts); err != nil { if allowedUpdateIps, err = ipsFromHosts(updateHosts); err != nil {

View File

@ -196,10 +196,17 @@ func (tu *tileUpdater) doUpdates() {
jobs := make(chan *xzc) jobs := make(chan *xzc)
var done sync.WaitGroup var done sync.WaitGroup
var proto string
if strings.ContainsRune(tu.redisAddress, '/') {
proto = "unix"
} else {
proto = "tcp"
}
for i, n := 0, common.Min(tu.workers, len(changes)); i < n; i++ { for i, n := 0, common.Min(tu.workers, len(changes)); i < n; i++ {
var client *common.RedisClient var client *common.RedisClient
var err error var err error
if client, err = common.NewRedisClient("tcp", tu.redisAddress); err != nil { if client, err = common.NewRedisClient(proto, tu.redisAddress); err != nil {
log.Printf("WARN: Cannot connect to redis server: %s\n", err) log.Printf("WARN: Cannot connect to redis server: %s\n", err)
continue continue
} }