Skip to content
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
1 change: 1 addition & 0 deletions cspell-allow-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ rbacs
readwrite
reclone
recloning
rediss
reexecuting
referer
refreshable
Expand Down
32 changes: 21 additions & 11 deletions docs/self-hosted/external-services/redis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@

**Version requirements**: We support any version _starting from 6.2_. Redis Cluster and Redis Sentinel are not supported.

Generally, there is no reason to do this as Sourcegraph only stores ephemeral cache and session data in Redis. However, if you want to use an external Redis server with Sourcegraph, you can follow the deployment specific guidance below:
Generally, there is no reason to do this as Sourcegraph only stores ephemeral cache and session data in Redis. However, if you want to use an external Redis server with Sourcegraph, you can follow the deployment specific guidance below.

## Single-container
Sourcegraph uses two Redis instances, configured with these environment variables:

Add the `REDIS_ENDPOINT` environment variable to your `docker run` command and Sourcegraph will use that Redis server instead of its built-in one. The string must either have the format `$HOST:PORT`
or follow the [IANA specification for Redis URLs](https://www.iana.org/assignments/uri-schemes/prov/redis) (e.g., `redis://:mypassword@host:6379/2`). For example:
- `REDIS_CACHE_ENDPOINT` for cached data. Set `maxmemory-policy allkeys-lru` on this instance; the frontend logs a warning on startup if it is not set.
- `REDIS_STORE_ENDPOINT` for persistent data, such as user sessions and locks. Set `maxmemory-policy noeviction` on this instance.

```
docker run [...]
-e REDIS_ENDPOINT=redis.example.com:6379
sourcegraph/server:{CURRENT_VERSION}
```
Each value is either `host:port`, or a URL following the [IANA specification for Redis URLs](https://www.iana.org/assignments/uri-schemes/prov/redis), such as `redis://:mypassword@redis-store.example.com:6379/0`. Use the `rediss://` scheme for a TLS connection.

> NOTE: On Mac/Windows, if trying to connect to a Redis server on the same host machine, remember that Sourcegraph is running inside a Docker container inside of the Docker virtual machine. You may need to specify your actual machine IP address and not `localhost` or `127.0.0.1` as that refers to the Docker VM itself.
## Docker Compose

If using Docker for Desktop, `host.docker.internal` will resolve to the host IP address.
Set both environment variables on every service that connects to Redis:

- `sourcegraph-frontend-0`
- `sourcegraph-frontend-internal`
- `gitserver-0`
- `searcher-0`
- `worker`
- `precise-code-intel-worker`
- `syntactic-code-intel-worker`

A service without them keeps connecting to the built-in `redis-cache` and `redis-store` containers.

1. Copy the [external Redis example](https://github.com/sourcegraph/deploy-sourcegraph-docker/blob/main/docker-compose/examples/external-redis/docker-compose.override.yaml) into your `docker-compose.override.yaml`. It sets the variables on these services and disables the built-in Redis containers.
2. Replace the example values of `REDIS_CACHE_ENDPOINT` and `REDIS_STORE_ENDPOINT` with your Redis endpoints.
3. Apply the change with `docker compose up -d --remove-orphans`.

## Kubernetes

Expand Down
Loading