> ## 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` 並按下 Enter 鍵以離開 redis-cli
9. 輸入 `exit` 並按下 Enter 鍵以離開 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.