go-disque
go-disque copied to clipboard
Return pure redis.ErrNil, so 'nil return' can be detected.
redis.ErrNil can be easily detected and a timeout is got, which is different from other errors.
why can't you detect nil the usual way? formatting the way I do is the recommended way in go.
An example:
if jobs, err := client.GetMulti(10, 20*time.Second, queues...); err != nil && err != redis.ErrNil {
log.Println(err)
}
If jobs
is nil, there may be an error. But if the error is redis.ErrNil
, I will know this is timeout and not other errors. Then I can start this observation again and it is not considered as a real error. If the error is not this, I must record it.
I'd rather handle this case internally and not trust redigo errors, I might change the internal client, I don't want to commit to keeping redigo under the hood. Also, why is a timeout ErrNil?
You can jump in this line.
vals, err := redis.Values(c.conn.Do("GETJOB", args...))
And the err
returned here for a timeout is redis.ErrNil
.
If you don't want to keep redigo, you can also define an error type such as disque.ErrNil
like redigo does. And then return it if there is a timeout.