You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove APIs for separate init and connect of async cluster contexts (#165)
Embed a `valkeyClusterContext` in a created `valkeyClusterAsyncContext`
to be able to cast between these types. This enables users to access the
async context in an event callback without using `privdata`, and we can
remove the APIs previously kept just for this scenario:
valkeyClusterAsyncContext *valkeyClusterAsyncContextInit(const valkeyClusterOptions *options);
int valkeyClusterAsyncConnect(valkeyClusterAsyncContext *acc);
int valkeyClusterAsyncSetEventCallback(valkeyClusterAsyncContext *acc,
void(fn)(const valkeyClusterContext *cc,
int event, void *privdata),
Also removing the testcase based on `clusterclient_reconnect_async.c`
since it was using the removed APIs.
There is now a symmetry to how standalone contexts works, i.e.
`valkeyAsyncContext` embeds the `valkeyContext`.
Signed-off-by: Björn Svensson <[email protected]>
Copy file name to clipboardExpand all lines: docs/cluster.md
+11-25Lines changed: 11 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -193,8 +193,9 @@ The callback is called with `event` set to one of the following values:
193
193
* `VALKEYCLUSTER_EVENT_SLOTMAP_UPDATED` when the slot mapping has been updated;
194
194
* `VALKEYCLUSTER_EVENT_READY` when the slot mapping has been fetched for the first
195
195
time and the client is ready to accept commands, useful when initiating the
196
-
client with `valkeyClusterAsyncConnect` where a client is not immediately
197
-
ready after a successful call;
196
+
client using `valkeyClusterAsyncConnectWithOptions` without enabling the option
197
+
`VALKEY_OPT_BLOCKING_INITIAL_UPDATE` where a client is not immediately ready
198
+
after a successful call;
198
199
* `VALKEYCLUSTER_EVENT_FREE_CONTEXT` when the cluster context is being freed, so
199
200
that the user can free the event `privdata`.
200
201
@@ -255,26 +256,6 @@ When enabled `valkeyClusterAsyncConnectWithOptions` will initially connect to th
255
256
Any command sent by the user thereafter will create a new non-blocking connection, unless a non-blocking connection already exists to the destination.
256
257
The function returns a pointer to a newly created `valkeyClusterAsyncContext` struct and its `err` field should be checked to make sure the initial slot map update was successful.
257
258
258
-
There is also a separate API to perform the context initiation and initial connect in separate steps.
259
-
This is useful when there is a need to provide an event callback with the current `valkeyClusterAsyncContext`.
260
-
The context is first initiated using `valkeyClusterAsyncContextInit` and then `valkeyClusterAsyncConnect` will initiate connection attempts.
There is a variety of options you can specify using the `valkeyClusterOptions` struct when connecting to a cluster.
@@ -339,9 +320,14 @@ After this, the disconnection callback is executed with the `VALKEY_OK` status a
339
320
340
321
Use [`event_callback` in `valkeyClusterOptions`](#events-per-cluster-context) to get notified when certain events occur.
341
322
342
-
When the callback function requires the current `valkeyClusterAsyncContext` it can be provided in the `privdata`.
343
-
In this case initiate the context using `valkeyClusterAsyncContextInit`, set the callback and `privdata` using `valkeyClusterAsyncSetEventCallback`,
344
-
and initiate connection attempts using `valkeyClusterAsyncConnect` as described under the [Connecting](#connecting-1) section.
323
+
When the callback function requires the current `valkeyClusterAsyncContext`, it can typecast the given `valkeyClusterContext` to a `valkeyClusterAsyncContext`.
324
+
The `valkeyClusterAsyncContext` struct is an extension of the `valkeyClusterContext` struct.
325
+
326
+
```c
327
+
void eventCallback(const valkeyClusterContext *cc, int event, void *privdata) {
Copy file name to clipboardExpand all lines: docs/migration-guide.md
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,8 @@ The type `sds` is removed from the public API.
36
36
initiation examples that might be helpful.
37
37
* The default command to update the internal slot map is changed to `CLUSTER SLOTS`.
38
38
`CLUSTER NODES` can be re-enabled through options using `VALKEY_OPT_USE_CLUSTER_NODES`.
39
+
* A `valkeyClusterAsyncContext` now embeds a `valkeyClusterContext` instead of
40
+
holding a pointer to it. Replace any use of `acc->cc` with `&acc->cc` or similar.
39
41
40
42
### Renamed API functions
41
43
@@ -61,10 +63,13 @@ The type `sds` is removed from the public API.
61
63
*`redisClusterSetOptionConnectNonBlock` removed since it was deprecated.
62
64
*`redisClusterSetOptionConnectTimeout` removed, use `valkeyClusterOptions.connect_timeout`.
63
65
*`redisClusterSetOptionMaxRetry` removed, use `valkeyClusterOptions.max_retry`.
64
-
*`redisClusterSetOptionParseSlaves` removed, use `valkeyClusterOptions.flags` and `VALKEY_OPT_USE_REPLICAS`.
66
+
*`redisClusterSetOptionParseSlaves` removed, use `valkeyClusterOptions.options` and `VALKEY_OPT_USE_REPLICAS`.
65
67
*`redisClusterSetOptionPassword` removed, use `valkeyClusterOptions.password`.
66
-
*`redisClusterSetOptionRouteUseSlots` removed, the use of `CLUSTER SLOTS` is enabled by default.
68
+
*`redisClusterSetOptionRouteUseSlots` removed, `CLUSTER SLOTS` is used by default.
67
69
*`redisClusterSetOptionUsername` removed, use `valkeyClusterOptions.username`.
70
+
*`redisClusterAsyncConnect` removed, use `valkeyClusterAsyncConnectWithOptions` with options flag `VALKEY_OPT_BLOCKING_INITIAL_UPDATE`.
71
+
*`redisClusterAsyncConnect2` removed, use `valkeyClusterAsyncConnectWithOptions`.
72
+
*`redisClusterAsyncContextInit` removed, `valkeyClusterAsyncConnectWithOptions` will initiate the context.
68
73
*`redisClusterAsyncSetConnectCallback` removed, but `valkeyClusterOptions.async_connect_callback` can be used which accepts a non-const callback function prototype.
69
74
*`redisClusterAsyncSetConnectCallbackNC` removed, use `valkeyClusterOptions.async_connect_callback`.
70
75
*`redisClusterAsyncSetDisconnectCallback` removed, use `valkeyClusterOptions.async_disconnect_callback`.
0 commit comments