Update README with new way of handling errors
This commit is contained in:
parent
56bbeb7049
commit
808e43e161
17
README.md
17
README.md
|
@ -35,16 +35,17 @@ To consume the synchronous API, there are only a few function calls that need to
|
||||||
|
|
||||||
### Connecting
|
### Connecting
|
||||||
|
|
||||||
The function `redisConnect` is used to create a so-called `redisContext`. The context is where
|
The function `redisConnect` is used to create a so-called `redisContext`. The
|
||||||
Hiredis holds state for a connection. The `redisContext` struct has an `error` field that is
|
context is where Hiredis holds state for a connection. The `redisContext`
|
||||||
non-NULL when the connection is in an error state. It contains a string with a textual
|
struct has an integer `err` field that is non-zero when an the connection is in
|
||||||
representation of the error. After trying to connect to Redis using `redisConnect` you should
|
an error state. The field `errstr` will contain a string with a description of
|
||||||
check the `error` field to see if establishing the connection was successful:
|
the error. After trying to connect to Redis using `redisConnect` you should
|
||||||
|
check the `err` field to see if establishing the connection was successful:
|
||||||
|
|
||||||
redisContext *c = redisConnect("127.0.0.1", 6379);
|
redisContext *c = redisConnect("127.0.0.1", 6379);
|
||||||
if (c->error != NULL) {
|
if (c->err) {
|
||||||
printf("Error: %s\n", c->error);
|
printf("Error: %s\n", c->errstr);
|
||||||
// handle error
|
// handle error
|
||||||
}
|
}
|
||||||
|
|
||||||
### Sending commands
|
### Sending commands
|
||||||
|
|
Loading…
Reference in New Issue
Block a user