Skip to content

Commit

Permalink
Move missing information from libvalkey/README.md
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Sep 2, 2024
1 parent 5867289 commit 39c564d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 774 deletions.
25 changes: 24 additions & 1 deletion docs/standalone.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ This document describes using `libvalkey` in standalone (non-cluster) mode, incl
- [Asynchronous API](#asynchronous-api)
- [Connecting](#connecting-1)
- [Executing commands](#executing-commands-1)
- [Disconnecting/cleanup](#disconnecting-cleanup-1)
- [SSL/TLS support](#ssl-tls-support)

## Synchronous API

Expand Down Expand Up @@ -314,6 +316,11 @@ valkeySetDisconnectCallback(ac, my_disconnect_callback);
ev_run(EV_DEFAULT_ 0);
```
The asynchronous context _should_ hold a connect callback function that is called when the connection attempt completes, either successfully or with an error.
It _can_ also hold a disconnect callback function that is called when the connection is disconnected (either because of an error or per user request).
The context object is always freed after the disconnect callback fired.
### Executing commands
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.
Expand Down Expand Up @@ -348,5 +355,21 @@ 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");
}
```

### Disconnecting/cleanup

For a graceful disconnect use `valkeyAsyncDisconnect` which will block new commands from being issued.
The connection is only terminated when all pending commands have been sent, their respective replies have been read, and their respective callbacks have been executed.
After this, the disconnection callback is called with the status, and the context object is freed.

To terminate the connection forcefully use `valkeyAsyncFree` which also will block new commands from being issued.
There will be no more data sent on the socket and all pending callbacks will be called with a `NULL` reply.
After this, the disconnection callback is called with the `VALKEY_OK` status, and the context object is freed.

## SSL/TLS support

SSL/TLS support is not enabled by default and requires an explicit build flag as described in [`README.md`](../README.md#building).

Libvalkey implements SSL/TLS on top of its `valkeyContext` and `valkeyAsyncContext`, so you will need to establish a connection first and then initiate an SSL/TLS handshake.
See the [examples](../examples) directory for how to create the SSL/TLS context and initiate the handshake.
4 changes: 4 additions & 0 deletions include/valkey/valkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,13 @@ int valkeyReconnect(valkeyContext *c);

valkeyPushFn *valkeySetPushCallback(valkeyContext *c, valkeyPushFn *fn);
int valkeySetTimeout(valkeyContext *c, const struct timeval tv);

/* Configurations using socket options. Applied directly to the underlying
* socket and not automatically applied after a reconnect. */
int valkeyEnableKeepAlive(valkeyContext *c);
int valkeyEnableKeepAliveWithInterval(valkeyContext *c, int interval);
int valkeySetTcpUserTimeout(valkeyContext *c, unsigned int timeout);

void valkeyFree(valkeyContext *c);
valkeyFD valkeyFreeKeepFd(valkeyContext *c);
int valkeyBufferRead(valkeyContext *c);
Expand Down
Loading

0 comments on commit 39c564d

Please sign in to comment.