hibiken/asynq · error
asynq: could not parse redis sentinel uri: database number…
Error message
asynq: could not parse redis sentinel uri: database number should be the first segment of the path
What it means
Guard in parseRedisSentinelURI: the redis-sentinel: URI has a path whose first segment is not a number (e.g. /foo or /abc/1). Per the URI format, the database number must be the first path segment, so strconv.Atoi fails and the URI is rejected.
Solutions
- Make the first path segment of the sentinel URI a valid integer database number, e.g. 'redis-sentinel:host:26379/2?master=mymaster'
- Remove the path entirely if the default database (0) is desired, since an empty path skips parsing
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at asynq.go:555 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of hibiken/asynq@d135f1439b (2026-09-07).
Data as JSON: /api/errors/7a9dbfb8ff3f9004.
Report an issue: GitHub.
Appendix: source
Thrown at asynq.go:555
}
}
var password string
if v, ok := u.User.Password(); ok {
password = v
}
return RedisClientOpt{Network: "unix", Addr: u.Path, DB: db, Password: password}, nil
}
func parseRedisSentinelURI(u *url.URL) (RedisConnOpt, error) {
addrs := strings.Split(u.Host, ",")
master := u.Query().Get("master")
var db int
var err error
if len(u.Path) > 0 {
xs := strings.Split(strings.Trim(u.Path, "/"), "/")
db, err = strconv.Atoi(xs[0])
if err != nil {
return nil, fmt.Errorf("asynq: could not parse redis sentinel uri: database number should be the first segment of the path")
}
}
var password string
if v, ok := u.User.Password(); ok {
password = v
}
return RedisFailoverClientOpt{MasterName: master, SentinelAddrs: addrs, SentinelPassword: password, DB: db}, nil
}
// ResultWriter is a client interface to write result data for a task.
// It writes the data to the redis instance the server is connected to.
type ResultWriter struct {
id string // task ID this writer is responsible for
qname string // queue name the task belongs to
broker base.Broker
ctx context.Context // context associated with the task
}
View on GitHub (pinned to d135f1439b)