Skip to content

Commit

Permalink
Merge pull request #3 from redis/main
Browse files Browse the repository at this point in the history
Changes for (Add IsParseError() documentation redis#578) (redis#581)
  • Loading branch information
SoulPancake authored Jun 29, 2024
2 parents 45cdf7e + b19f550 commit 66e53fa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 66e53fa

Please sign in to comment.