MCPcopy
hub / github.com/redis/go-redis / IsMovedError

Function IsMovedError

internal/proto/redis_errors.go:335–353  ·  view source on GitHub ↗

IsMovedError checks if an error is a MovedError, even if wrapped. Returns the error and a boolean indicating if it's a MovedError.

(err error)

Source from the content-addressed store, hash-verified

333// IsMovedError checks if an error is a MovedError, even if wrapped.
334// Returns the error and a boolean indicating if it's a MovedError.
335func IsMovedError(err error) (*MovedError, bool) {
336 if err == nil {
337 return nil, false
338 }
339 var movedErr *MovedError
340 if errors.As(err, &movedErr) {
341 return movedErr, true
342 }
343 // Fallback to string checking for backward compatibility
344 s := err.Error()
345 if strings.HasPrefix(s, "MOVED ") {
346 // Parse: MOVED 3999 127.0.0.1:6381
347 parts := strings.Split(s, " ")
348 if len(parts) == 3 {
349 return &MovedError{msg: s, addr: parts[2]}, true
350 }
351 }
352 return nil, false
353}
354
355// IsAskError checks if an error is an AskError, even if wrapped.
356// Returns the error and a boolean indicating if it's an AskError.

Callers 5

isMovedErrorFunction · 0.92
isMovedSameConnAddrFunction · 0.92
IsMovedErrorFunction · 0.92
TestTypedRedisErrorsFunction · 0.70

Calls 1

ErrorMethod · 0.45

Tested by 2

TestTypedRedisErrorsFunction · 0.56