From b19f55062065b057e11e7d8f9804e4935dbb13ff Mon Sep 17 00:00:00 2001 From: Karim Al Zalek <109340153+karimalzalek@users.noreply.github.com> Date: Fri, 28 Jun 2024 16:36:34 +0400 Subject: [PATCH] Changes for (Add IsParseError() documentation #578) (#581) * Changes for (Add IsParseError() documentation #578) * Changes for (Add IsParseError() documentation #578) * Changes for (Add IsParseError() documentation #578) * Delete .vscode/settings.json Removing wrong settings.json file * Update README.md Co-authored-by: Anurag Bandyopadhyay --------- Co-authored-by: Anurag Bandyopadhyay --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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: