> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Redis

### 启用密码认证

如果你使用外部 Redis 服务并需要提供密码，可以在 **config/variables.env** 文件中设置 `OVERLEAF_REDIS_PASS` 和 `REDIS_PASSWORD` 环境变量，然后运行 `bin/up -d` 命令重新创建 **sharelatex** 容器。

如果你运行的是本地 Redis 实例，则需要将 **redis** 服务配置为以密码认证方式启动。设置上述环境变量后，你还需要完成以下额外步骤：

在 <strong>config/</strong> 目录中创建一个 **docker-compose.override.yml** 文件，内容如下：

```yaml title="config/docker-compose.override.yml" theme={null}
services:
    redis:
        command: "redis-server --requirepass <YOUR-PASSWORD>"
```

<Warning>
  如果你启用了 AOF 持久化，则需要在 `command` 中添加 `--appendonly yes`。
</Warning>

运行 `bin/up -d` 重新创建容器。

### 启用 Append-Only File 持久化

（原文：[https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/redis#enabling-append-only-file-persistence）](https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/redis#enabling-append-only-file-persistence）)

Redis AOF（Append-Only File）持久化通过记录服务器收到的每个写操作，提供了一种可靠的方式来确保数据持久性。与对数据集进行时间点拷贝的 RDB 快照不同，AOF 会完整记录对数据所做的所有更改。

<Info>
  禁用 RDB 是可选的。通常建议同时使用这两种持久化方式。在生产环境中进行任何更改之前，请先了解同时运行 AOF 和 RDB 的优缺点。
</Info>

你可以在此处阅读有关在 Redis 中启用 AOF 持久化的更多信息：[https://redis.io/docs/latest/operate/oss\_and\_stack/management/persistence/#how-i-can-switch-to-aof-if-im-currently-using-dumprdb-snapshotsarrow-up-right](https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/#how-i-can-switch-to-aof-if-im-currently-using-dumprdb-snapshotsarrow-up-right)

1. 为升级安排一个维护窗口。
2. 使用 `bin/stop` 停止实例，并备份 <strong>config/</strong> 和 <strong>data/</strong> 文件夹。
3. 运行 `bin/up` 启动实例
4. 运行命令 `docker exec -it redis sh`
5. 运行命令 `redis-cli` 打开 Redis 命令行界面
6. 在 redis-cli 中运行命令 `config set appendonly yes`
7. 现在你需要等待 AOF 重写完成数据持久化。你可以在 redis-cli 中输入 `INFO persistence`，等待 `aof_rewrite_in_progress` 和 `aof_rewrite_scheduled` 变为 `0`，并确认 `aof_last_bgrewrite_status` 为 `ok`。
8. 输入 `exit` 并按回车键退出 redis-cli
9. 输入 `exit` 并按回车键退出 redis 容器
10. 运行命令 `ls ./data/redis`，确认可以看到 **appendonly.aof** 文件
11. 编辑 **config/overleaf.rc** 文件，将 `REDIS_AOF_PERSISTENCE` 环境变量从 `false` 改为 `true`
12. 运行 `bin/up -d` 并确保应用正常工作（项目编辑器和历史记录面板功能正常）。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.