Skip to content

Commit

Permalink
Changes for (Add IsParseError() documentation redis#578) (redis#581)
Browse files Browse the repository at this point in the history
* Changes for (Add IsParseError() documentation redis#578)

* Changes for (Add IsParseError() documentation redis#578)

* Changes for (Add IsParseError() documentation redis#578)

* Delete .vscode/settings.json

Removing wrong settings.json file

* Update README.md

Co-authored-by: Anurag Bandyopadhyay <[email protected]>

---------

Co-authored-by: Anurag Bandyopadhyay <[email protected]>
  • Loading branch information
karimalzalek and SoulPancake authored Jun 28, 2024
1 parent 45cdf7e commit b19f550
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 b19f550

Please sign in to comment.