Redis: How to check redis error type

Created on 25 Sep 2017  路  3Comments  路  Source: go-redis/redis

Hey guys, go-redis will return an error if I HGet a hash field which doesn't exist.
But how do i distinguish this error with other errors like network error?
What i want to do is:

val, err := redis.HGet("hash", "not_exist_field")
if err.(???) {
   log.Println("ok, the field does not exist, make it default to 0")
} else {
   log.Println("some unknow error occurs, log it and return err to caller")
}

Most helpful comment

You are probably looking for redis.Nil

All 3 comments

You are probably looking for redis.Nil

@vmihailenco Thanks! This is exactly what I'm looking for. Just wondering why making nil response an error instead of a normal return value?

Like what?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Turing-Chu picture Turing-Chu  路  3Comments

krak3n picture krak3n  路  4Comments

aahoughton picture aahoughton  路  5Comments

youcandoit95 picture youcandoit95  路  3Comments

patrickwhite256 picture patrickwhite256  路  7Comments