Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document the Redis URL format #3556

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changesets/docs_geal_redis_connection_schemes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### Document the Redis URL format ([Issue #3534](https://github.com/apollographql/router/issues/3534))

The Redis client used in the Router follows a convention on Redis server URLs to indicate TLS, cluster or sentinel usage


By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/3556
57 changes: 55 additions & 2 deletions docs/source/configuration/distributed-caching.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,59 @@ Whenever a router instance requires a query plan or APQ query string to resolve
3. If _not_ found, the router instance _generates_ the required query plan or requests the full operation string from the client for APQ.
4. The router instance stores the obtained value in both the distributed cache _and_ its in-memory cache.

## Redis URL configuration

The distributed caching configuration must contain one or more URLs using different schemes depending on the expected deployment:

* `redis` - TCP connected to a centralized server.
* `rediss` - TLS connected to a centralized server.
* `redis-cluster` - TCP connected to a cluster.
* `rediss-cluster` - TLS connected to a cluster.
* `redis-sentinel` - TCP connected to a centralized server behind a sentinel layer.
* `rediss-sentinel` - TLS connected to a centralized server behind a sentinel layer.

The URLs must have the following format:

### One node

```
redis|rediss :// [[username:]password@] host [:port][/database]
```

Example: `redis://localhost:6379`

### Clustered

```
redis|rediss[-cluster] :// [[username:]password@] host [:port][?[node=host1:port1][&node=host2:port2][&node=hostN:portN]]
```

or, if configured with multiple URLs:

```
[
"redis|rediss[-cluster] :// [[username:]password@] host [:port]",
"redis|rediss[-cluster] :// [[username:]password@] host1 [:port1]",
"redis|rediss[-cluster] :// [[username:]password@] host2 [:port2]"
]
```

### Sentinel

```
redis|rediss[-sentinel] :// [[username1:]password1@] host [:port][/database][?[node=host1:port1][&node=host2:port2][&node=hostN:portN]
[&sentinelServiceName=myservice][&sentinelUsername=username2][&sentinelPassword=password2]]
```

or, if configured with multiple URLs:

```
[
"redis|rediss[-sentinel] :// [[username:]password@] host [:port][/database][?[&sentinelServiceName=myservice][&sentinelUsername=username2][&sentinelPassword=password2]]",
"redis|rediss[-sentinel] :// [[username1:]password1@] host [:port][/database][?[&sentinelServiceName=myservice][&sentinelUsername=username2][&sentinelPassword=password2]]"
]
```

## Distributed query plan caching

To enable distributed caching of query plans, add the following to your router's [YAML config file](./overview/#yaml-config-file):
Expand All @@ -37,7 +90,7 @@ supergraph:
urls: ["redis://..."] #highlight-line
```

The value of `urls` is a list of URLs for all Redis instances in your cluster. These can be `redis://` or `rediss://` URLs.
The value of `urls` is a list of URLs for all Redis instances in your cluster.

> ⚠️ **You should specify your Redis URLs via environment variables and [variable expansion](./overview#variable-expansion)**. This prevents your Redis URLs from being committed to version control, which is especially dangerous if they include authentication information like a username and/or password.

Expand All @@ -53,6 +106,6 @@ apq:
urls: ["redis://..."] #highlight-line
```

The value of `urls` is a list of URLs for all Redis instances in your cluster. These can be `redis://` or `rediss://` URLs.
The value of `urls` is a list of URLs for all Redis instances in your cluster.

> ⚠️ **You should specify your Redis URLs via environment variables and [variable expansion](./overview#variable-expansion)**. This prevents your Redis URLs from being committed to version control, which is especially dangerous if they include authentication information like a username and/or password.