Skip to content

How to check redis error type #645

@mouhong

Description

@mouhong

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")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions