diff --git a/README.md b/README.md index 119f66a0..327440f7 100644 --- a/README.md +++ b/README.md @@ -434,8 +434,19 @@ n, resp, err := client.Do(ctx, cmd).AsFtSearch() ## Command Response Cheatsheet -While the command builder is developer-friendly, the response parser is a little unfriendly. Developers must know what -type of Redis response will be returned from the server beforehand and which parser they should use. Otherwise, it panics. +While the command builder is developer-friendly, the response parser is a little unfriendly. Developers must know what type of Redis response will be returned from the server beforehand and which parser they should use. + +Error Handling: +If an incorrect parser function is chosen, an errParse will be returned. Here's an example using ToArray which demonstrates this scenario: + +```golang +// Attempt to parse the response. If a parsing error occurs, check if the error is a parse error and handle it. +// Normally, you should fix the code by choosing the correct parser function. +// For instance, use ToString() if the expected response is a string, or ToArray() if the expected response is an array as follows: +if err := client.Do(ctx, client.B().Get().Key("k").Build()).ToArray(); IsParseErr(err) { + fmt.Println("Parsing error:", err) +} +``` It is hard to remember what type of message will be returned and which parsing to use. So, here are some common examples: