Redis: Looks like redis.Nil is broken

Created on 13 Nov 2020  路  2Comments  路  Source: go-redis/redis

Issue tracker is used for reporting bugs and discussing new features. Please use
stackoverflow for supporting issues.

Currently the basic error checking for redis.Nil is not working. See sample code below

Expected Behavior

redis.Nil should match the error or errors.Is should match it

Current Behavior

Neither errors.Is nor == match redis.Nil

Steps to Reproduce

key := "non_existing_key"
log.Debugf("getting redis key %s", key)
val, err := app.redisClient.Get(ctx, key).Result()
log.Printf("A: %v", err == redis.Nil)
log.Printf("B: %v", errors.Is(err, redis.Nil))
log.Printf("C: %v", reflect.DeepEqual(err, redis.Nil))
if err != nil {
    if errors.Is(err, redis.Nil) {
        log.Debug("errors is")
        return 0, nil
    } else if err == redis.Nil {
        log.Debug("equals redis.Nil")
        return 0, nil
    } else {
        log.Debug("else")
        log.Debugf("%+v", err)
        log.Debugf("%+v", redis.Nil)
        return -1, err
    }
}

Output:

| time="2020-11-13T12:13:36Z" level=info msg="A: false"
| time="2020-11-13T12:13:36Z" level=info msg="B: false"
| time="2020-11-13T12:13:36Z" level=info msg="C: false"
| time="2020-11-13T12:13:36Z" level=debug msg=else
| time="2020-11-13T12:13:36Z" level=debug msg="redis: nil"
| time="2020-11-13T12:13:36Z" level=debug msg="redis: nil"

Context (Environment)

go-redis: 8.3.3
go version go1.15.5 linux/amd64


Most helpful comment

If someone comes about this again:
I had an old "github.com/go-redis/redis" import left (instead of "github.com/go-redis/redis/v8") which caused this weird error

All 2 comments

If someone comes about this again:
I had an old "github.com/go-redis/redis" import left (instead of "github.com/go-redis/redis/v8") which caused this weird error

If someone comes about this again:
I had an old "github.com/go-redis/redis" import left (instead of "github.com/go-redis/redis/v8") which caused this weird error

Saved my butt. Go lang is automagically importing the older version. Thanks for the follow up.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ihsw picture ihsw  路  5Comments

MaerF0x0 picture MaerF0x0  路  7Comments

Turing-Chu picture Turing-Chu  路  3Comments

krak3n picture krak3n  路  4Comments

mathvav picture mathvav  路  3Comments