Skip to content

Commit

Permalink
feat: add rueidis.Nil
Browse files Browse the repository at this point in the history
  • Loading branch information
rueian committed Dec 16, 2022
1 parent 5d32787 commit 873a2fd
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (

const messageStructSize = int(unsafe.Sizeof(RedisMessage{}))

// Nil represents a Redis Nil message
var Nil = &RedisError{typ: '_'}

// IsRedisNil is a handy method to check if error is redis nil response.
// All redis nil response returns as an error.
func IsRedisNil(err error) bool {
if e, ok := err.(*RedisError); ok {
return e.IsNil()
}
return false
return err == Nil
}

// RedisError is an error response or a nil message from redis instance
Expand Down Expand Up @@ -403,8 +403,7 @@ func (m *RedisMessage) IsMap() bool {
// Error check if message is a redis error response, including nil response
func (m *RedisMessage) Error() error {
if m.typ == '_' {
mm := *m
return (*RedisError)(&mm)
return Nil
}
if m.typ == '-' || m.typ == '!' {
// kvrocks: https://github.com/rueian/rueidis/issues/152#issuecomment-1333923750
Expand Down

0 comments on commit 873a2fd

Please sign in to comment.