@@ -11,6 +11,8 @@ import (
11
11
"strconv"
12
12
"strings"
13
13
14
+ "code.gitea.io/gitea/modules/log"
15
+
14
16
"github.com/go-redis/redis/v8"
15
17
)
16
18
@@ -76,30 +78,13 @@ func (m *Manager) GetRedisClient(connection string) redis.UniversalClient {
76
78
opts .TLSConfig = tlsConfig
77
79
fallthrough
78
80
case "redis+sentinel" :
79
- if uri .Host != "" {
80
- opts .Addrs = append (opts .Addrs , strings .Split (uri .Host , "," )... )
81
- }
82
- if uri .Path != "" {
83
- if db , err := strconv .Atoi (uri .Path [1 :]); err == nil {
84
- opts .DB = db
85
- }
86
- }
87
-
88
81
client .UniversalClient = redis .NewFailoverClient (opts .Failover ())
89
82
case "redis+clusters" :
90
83
fallthrough
91
84
case "rediss+cluster" :
92
85
opts .TLSConfig = tlsConfig
93
86
fallthrough
94
87
case "redis+cluster" :
95
- if uri .Host != "" {
96
- opts .Addrs = append (opts .Addrs , strings .Split (uri .Host , "," )... )
97
- }
98
- if uri .Path != "" {
99
- if db , err := strconv .Atoi (uri .Path [1 :]); err == nil {
100
- opts .DB = db
101
- }
102
- }
103
88
client .UniversalClient = redis .NewClusterClient (opts .Cluster ())
104
89
case "redis+socket" :
105
90
simpleOpts := opts .Simple ()
@@ -110,14 +95,6 @@ func (m *Manager) GetRedisClient(connection string) redis.UniversalClient {
110
95
opts .TLSConfig = tlsConfig
111
96
fallthrough
112
97
case "redis" :
113
- if uri .Host != "" {
114
- opts .Addrs = append (opts .Addrs , strings .Split (uri .Host , "," )... )
115
- }
116
- if uri .Path != "" {
117
- if db , err := strconv .Atoi (uri .Path [1 :]); err == nil {
118
- opts .DB = db
119
- }
120
- }
121
98
client .UniversalClient = redis .NewClient (opts .Simple ())
122
99
default :
123
100
return nil
@@ -215,6 +192,22 @@ func getRedisOptions(uri *url.URL) *redis.UniversalOptions {
215
192
}
216
193
}
217
194
195
+ if uri .Host != "" {
196
+ opts .Addrs = append (opts .Addrs , strings .Split (uri .Host , "," )... )
197
+ }
198
+
199
+ // A redis connection string uses the path section of the URI in two different ways. In a TCP-based connection, the
200
+ // path will be a database index to automatically have the client SELECT. In a Unix socket connection, it will be the
201
+ // file path. We only want to try to coerce this to the database index when we're not expecting a file path so that
202
+ // the error log stays clean.
203
+ if uri .Path != "" && uri .Scheme != "redis+socket" {
204
+ if db , err := strconv .Atoi (uri .Path [1 :]); err == nil {
205
+ opts .DB = db
206
+ } else {
207
+ log .Error ("Provided database identifier '%s' is not a valid integer. Gitea will ignore this option." , uri .Path )
208
+ }
209
+ }
210
+
218
211
return opts
219
212
}
220
213
0 commit comments