From 1fb9104009ed8a14182e90b13022b86364553d05 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Tue, 17 Dec 2019 19:44:37 +0000 Subject: [PATCH] Queue: Allow Redis to connect to unix --- modules/queue/queue_redis.go | 2 ++ modules/setting/queue.go | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/queue/queue_redis.go b/modules/queue/queue_redis.go index 4f2ceec029f..724e22b7b5d 100644 --- a/modules/queue/queue_redis.go +++ b/modules/queue/queue_redis.go @@ -41,6 +41,7 @@ type RedisQueue struct { // RedisQueueConfiguration is the configuration for the redis queue type RedisQueueConfiguration struct { + Network string Addresses string Password string DBIndex int @@ -88,6 +89,7 @@ func NewRedisQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue, error) return nil, errors.New("no redis host found") } else if len(dbs) == 1 { queue.client = redis.NewClient(&redis.Options{ + Network: config.Network, Addr: strings.TrimSpace(dbs[0]), // use default Addr Password: config.Password, // no password set DB: config.DBIndex, // use default DB diff --git a/modules/setting/queue.go b/modules/setting/queue.go index 5cbee851c64..778ddeb217f 100644 --- a/modules/setting/queue.go +++ b/modules/setting/queue.go @@ -22,6 +22,7 @@ type queueSettings struct { BatchLength int ConnectionString string Type string + Network string Addresses string Password string QueueName string @@ -47,6 +48,7 @@ func CreateQueue(name string, handle queue.HandlerFunc, exemplar interface{}) qu opts["BatchLength"] = q.BatchLength opts["DataDir"] = q.DataDir opts["Addresses"] = q.Addresses + opts["Network"] = q.Network opts["Password"] = q.Password opts["DBIndex"] = q.DBIndex opts["QueueName"] = q.QueueName @@ -111,7 +113,7 @@ func getQueueSettings(name string) queueSettings { q.BoostWorkers = sec.Key("BOOST_WORKERS").MustInt(Queue.BoostWorkers) q.QueueName = sec.Key("QUEUE_NAME").MustString(Queue.QueueName) - q.Addresses, q.Password, q.DBIndex, _ = ParseQueueConnStr(q.ConnectionString) + q.Network, q.Addresses, q.Password, q.DBIndex, _ = ParseQueueConnStr(q.ConnectionString) return q } @@ -128,7 +130,7 @@ func NewQueueService() { Queue.ConnectionString = sec.Key("CONN_STR").MustString(path.Join(AppDataPath, "")) validTypes := queue.RegisteredTypesAsString() Queue.Type = sec.Key("TYPE").In(string(queue.PersistableChannelQueueType), validTypes) - Queue.Addresses, Queue.Password, Queue.DBIndex, _ = ParseQueueConnStr(Queue.ConnectionString) + Queue.Network, Queue.Addresses, Queue.Password, Queue.DBIndex, _ = ParseQueueConnStr(Queue.ConnectionString) Queue.WrapIfNecessary = sec.Key("WRAP_IF_NECESSARY").MustBool(true) Queue.MaxAttempts = sec.Key("MAX_ATTEMPTS").MustInt(10) Queue.Timeout = sec.Key("TIMEOUT").MustDuration(GracefulHammerTime + 30*time.Second) @@ -183,7 +185,7 @@ func NewQueueService() { } // ParseQueueConnStr parses a queue connection string -func ParseQueueConnStr(connStr string) (addrs, password string, dbIdx int, err error) { +func ParseQueueConnStr(connStr string) (network, addrs, password string, dbIdx int, err error) { fields := strings.Fields(connStr) for _, f := range fields { items := strings.SplitN(f, "=", 2) @@ -191,6 +193,8 @@ func ParseQueueConnStr(connStr string) (addrs, password string, dbIdx int, err e continue } switch strings.ToLower(items[0]) { + case "network": + network = items[1] case "addrs": addrs = items[1] case "password":