Skip to content

Commit

Permalink
docs: note about manual context cancellation
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Nov 14, 2024
1 parent 9b34a38 commit 46be1c5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ This will also fall back `client.DoCache()` and `client.DoMultiCache()` to `clie

## Context Cancellation

`client.Do()`, `client.DoMulti()`, `client.DoCache()`, and `client.DoMultiCache()` can return early if the context is canceled or the deadline is reached.
`client.Do()`, `client.DoMulti()`, `client.DoCache()`, and `client.DoMultiCache()` can return early if the context deadline is reached.

```golang
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
Expand All @@ -226,6 +226,12 @@ client.Do(ctx, client.B().Set().Key("key").Value("val").Nx().Build()).Error() ==

Please note that though operations can return early, the command is likely sent already.

### Canceling a Context Before Its Deadline

Manually canceling a context is only work in pipeline mode, as it requires an additional goroutine to monitor the context.
Pipeline mode will be started automatically when there are concurrent requests on the same connection, but you can start it in advance with `ClientOption.AlwaysPipelining`
to make sure manually cancellation is respected, especially for blocking requests which are sent with a dedicated connection where pipeline mode isn't started.

## Pub/Sub

To receive messages from channels, `client.Receive()` should be used. It supports `SUBSCRIBE`, `PSUBSCRIBE`, and Redis 7.0's `SSUBSCRIBE`:
Expand Down

0 comments on commit 46be1c5

Please sign in to comment.