Skip to content

Commit

Permalink
Fix typo, add additional context
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-grunder committed Aug 6, 2024
1 parent 3a062e5 commit aed0154
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Libvalkey is the official C client for the [Valkey](https://valkey.io) database.
## Features

- Commands are executed in a generic way, with printf-like invocation.
- Supports both `RESP2` and `RESP3 protocol versions.
- Supports both `RESP2` and `RESP3` protocol versions.
- Supports both synchronous and asynchronous operation.
- Optional support for `SSL` and `RDMA` connections.
- Asynchronous API with several event libraries to choose from.
Expand Down Expand Up @@ -71,7 +71,7 @@ sudo make install

# Build with TLS and RDMA support
mkdir build && cd build
cmakd -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_SSL=1 -DENABLE_RDMA=1 ..
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_SSL=1 -DENABLE_RDMA=1 ..
sudo make install
```

Expand Down Expand Up @@ -269,10 +269,18 @@ Libvalkey has a few other mechanisms worth detailing in the README.
libvalkey uses a buffer to hold incomming bytes, which is typically restored to the configurable max buffer size (`16KB`) when it is empty. To avoid continually reallocating this buffer you can set the value higher, or to zero which means "no limit".
```c
context->reader->maxbuf = 0;
```

##### Maxelements

By default, libvalkey will refuse to parse array-like replies if they have more than 2^32-1 or 4,294,967,295 elements. This value can be set to any arbitrary 64-bit value or zero which just means "no limit".

```c
context->reader->maxelements = 0;
```

##### RESP3 Push Replies

The `RESP` protocol introduced out-of-band "push" replies in the third version of the specification. These replies may come at any point in the data stream. By default, libvalkey will simply process these messages and discard them.
Expand Down Expand Up @@ -323,7 +331,7 @@ valkeyAllocatorFuncs my_allocators = {
valkeyAllocFuncs old = valkeySetAllocators(&my_allocators);
```

They can also be reset to GLIBC/MUSL
They can also be reset to the glibc/musl defaults

```c
valkeyResetAllocators();
Expand Down Expand Up @@ -352,6 +360,7 @@ valkeyLibevAttach(EV_DEFAULT_ ac);

valkeySetConnectCallback(ac, my_connect_callback);
valkeySetDisconnectCallback(ac, my_disconnect_callback);

ev_run(EV_DEFAULT_ 0);
```
Expand All @@ -360,16 +369,36 @@ ev_run(EV_DEFAULT_ 0);
Executing commands in an asynchronous context work similarly to the synchronous context, except that you can pass a callback that will be invoked when the reply is received.
```c
struct my_app_data {
size_t incrby_replies;
size_t get_replies;
};
void my_incrby_callback(valkeyAsyncContext *ac, void *r, void *privdata) {
struct my_app_data *data = privdata;
valkeyReply *reply = r;
assert(reply != NULL && reply->type == VALKEY_REPLY_INTEGER);
printf("Incremented value: %lld\n", reply->integer);
data->incrby_replies++;
}
void my_get_callback(valkeyAsyncContext *ac, void *r, void *privdata) {
struct my_app_data *data = privdata;
valkeyReply *reply = r;
if (r == NULL) {
fprintf(stderr, "Error: %s\n", ac->errstr);
} else {
printf("Got reply: %s\n", r->str);
}
assert(reply != NULL && reply->type == VALKEY_REPLY_STRING);
printf("Key value: %s\n", reply->str);
data->get_replies++;
}
int exec_some_commands(struct my_app_data *data) {
valkeyAsyncCommand(ac, my_incrby_callback, data, "INCRBY mykey %d", 42);
valkeyAsyncCommand(ac, my_get_callback, data, "GET %s", "mykey");
}
valkeyAsyncCommand(ac, my_get_callback, NULL, "GET foo");
```

See the [examples](examples) directory for specific information on each supported event library.

0 comments on commit aed0154

Please sign in to comment.