go-disque icon indicating copy to clipboard operation
go-disque copied to clipboard

Return pure redis.ErrNil, so 'nil return' can be detected.

Open kakaLQY opened this issue 9 years ago • 4 comments

redis.ErrNil can be easily detected and a timeout is got, which is different from other errors.

kakaLQY avatar Jan 22 '16 07:01 kakaLQY

why can't you detect nil the usual way? formatting the way I do is the recommended way in go.

dvirsky avatar Jan 22 '16 10:01 dvirsky

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.

kakaLQY avatar Jan 22 '16 10:01 kakaLQY

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?

dvirsky avatar Jan 22 '16 11:01 dvirsky

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.

kakaLQY avatar Jan 22 '16 11:01 kakaLQY