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
redis.Nil should match the error or errors.Is should match it
Neither errors.Is nor == match redis.Nil
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"
go-redis: 8.3.3
go version go1.15.5 linux/amd64
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.
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