mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
Add redis prefix to errors
This commit is contained in:
parent
d31cf6c328
commit
9e4063ab5a
13
options.go
13
options.go
@ -206,7 +206,7 @@ func ParseURL(redisURL string) (*Options, error) {
|
|||||||
case "unix":
|
case "unix":
|
||||||
return setupUnixConn(u)
|
return setupUnixConn(u)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("invalid redis URL scheme: %s", u.Scheme)
|
return nil, fmt.Errorf("redis: invalid URL scheme: %s", u.Scheme)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ func setupTCPConn(u *url.URL) (*Options, error) {
|
|||||||
o.Username, o.Password = getUserPassword(u)
|
o.Username, o.Password = getUserPassword(u)
|
||||||
|
|
||||||
if len(u.Query()) > 0 {
|
if len(u.Query()) > 0 {
|
||||||
return nil, errors.New("no options supported")
|
return nil, errors.New("redis: no options supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
h, p, err := net.SplitHostPort(u.Host)
|
h, p, err := net.SplitHostPort(u.Host)
|
||||||
@ -239,10 +239,10 @@ func setupTCPConn(u *url.URL) (*Options, error) {
|
|||||||
o.DB = 0
|
o.DB = 0
|
||||||
case 1:
|
case 1:
|
||||||
if o.DB, err = strconv.Atoi(f[0]); err != nil {
|
if o.DB, err = strconv.Atoi(f[0]); err != nil {
|
||||||
return nil, fmt.Errorf("invalid redis database number: %q", f[0])
|
return nil, fmt.Errorf("redis: invalid database number: %q", f[0])
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("invalid redis URL path: %s", u.Path)
|
return nil, fmt.Errorf("redis: invalid URL path: %s", u.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.Scheme == "rediss" {
|
if u.Scheme == "rediss" {
|
||||||
@ -258,7 +258,7 @@ func setupUnixConn(u *url.URL) (*Options, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.TrimSpace(u.Path) == "" { // path is required with unix connection
|
if strings.TrimSpace(u.Path) == "" { // path is required with unix connection
|
||||||
return nil, errors.New("empty redis unix socket path")
|
return nil, errors.New("redis: empty unix socket path")
|
||||||
}
|
}
|
||||||
o.Addr = u.Path
|
o.Addr = u.Path
|
||||||
|
|
||||||
@ -268,9 +268,10 @@ func setupUnixConn(u *url.URL) (*Options, error) {
|
|||||||
if dbStr == "" {
|
if dbStr == "" {
|
||||||
return o, nil // if database is not set, connect to 0 db.
|
return o, nil // if database is not set, connect to 0 db.
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := strconv.Atoi(dbStr)
|
db, err := strconv.Atoi(dbStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid reids database number: %s", err)
|
return nil, fmt.Errorf("redis: invalid database number: %s", err)
|
||||||
}
|
}
|
||||||
o.DB = db
|
o.DB = db
|
||||||
|
|
||||||
|
@ -87,37 +87,37 @@ func TestParseURL(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"unix://foo:bar@/tmp/redis.sock?db=test",
|
"unix://foo:bar@/tmp/redis.sock?db=test",
|
||||||
"/tmp/redis.sock",
|
"/tmp/redis.sock",
|
||||||
0, false, errors.New("invalid reids database number: strconv.Atoi: parsing \"test\": invalid syntax"),
|
0, false, errors.New("redis: invalid database number: strconv.Atoi: parsing \"test\": invalid syntax"),
|
||||||
"", "",
|
"", "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"redis://localhost/?abc=123",
|
"redis://localhost/?abc=123",
|
||||||
"",
|
"",
|
||||||
0, false, errors.New("no options supported"),
|
0, false, errors.New("redis: no options supported"),
|
||||||
"", "",
|
"", "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"http://google.com",
|
"http://google.com",
|
||||||
"",
|
"",
|
||||||
0, false, errors.New("invalid redis URL scheme: http"),
|
0, false, errors.New("redis: invalid URL scheme: http"),
|
||||||
"", "",
|
"", "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"redis://localhost/1/2/3/4",
|
"redis://localhost/1/2/3/4",
|
||||||
"",
|
"",
|
||||||
0, false, errors.New("invalid redis URL path: /1/2/3/4"),
|
0, false, errors.New("redis: invalid URL path: /1/2/3/4"),
|
||||||
"", "",
|
"", "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"12345",
|
"12345",
|
||||||
"",
|
"",
|
||||||
0, false, errors.New("invalid redis URL scheme: "),
|
0, false, errors.New("redis: invalid URL scheme: "),
|
||||||
"", "",
|
"", "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"redis://localhost/iamadatabase",
|
"redis://localhost/iamadatabase",
|
||||||
"",
|
"",
|
||||||
0, false, errors.New(`invalid redis database number: "iamadatabase"`),
|
0, false, errors.New(`redis: invalid database number: "iamadatabase"`),
|
||||||
"", "",
|
"", "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user