Files
Olares/docs/zh/developer/develop/mw-integrate-with-redis.md
Meow33 776848d2e2 docs: add application environment variables (#2577)
* docs: updated installation env vars and runtime values references

* docs: fix content

* docs: update content

* Update table of contents, and refactored docs.

* Fixed capitalization.

* batch update to fix readability

* refactored declarative env var

* Updated translation.

* Updated based on suggestions.

* Updated based on suggestions.

---------

Co-authored-by: yajing wang <413741312@qq.com>
2026-03-05 17:52:22 +08:00

67 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
outline: [2, 3]
description: 了解如何在 Olares 中将应用接入内置的 Redis 服务。
---
# 集成 Redis
通过在 `OlaresManifest.yaml` 中声明依赖,并将系统注入的配置值映射到容器的环境变量中,即可在应用中使用 Olares 提供的 Redis 服务。
:::info Redis 已安装
Redis 服务在 Olares 中默认已安装。
:::
## 配置 `OlaresManifest.yaml`
`OlaresManifest.yaml` 中添加所需的中间件配置。
- 使用 `password` 字段指定 Redis 访问密码请求。
- 使用 `namespace` 字段申请 Redis 命名空间。
**示例**
```yaml
middleware:
redis:
password: password
namespace: db0
```
## 映射环境变量
在应用的部署 YAML 中,将系统注入的 `.Values.redis.*` 字段映射为应用所需的环境变量。
**示例**
```yaml
containers:
- name: my-app
env:
# 主机地址
- name: REDIS_HOST
value: {{ .Values.redis.host }}
# 端口
# 建议添加引号,确保作为字符串处理
- name: REDIS_PORT
value: "{{ .Values.redis.port }}"
# 密码
# 必须添加引号,以防止特殊字符导致解析错误
- name: REDIS_PASSWORD
value: "{{ .Values.redis.password }}"
# 命名空间
# 注意:请将 <namespace> 替换为 OlaresManifest 中定义的实际命名空间(例如 db0
- name: REDIS_NAMESPACE
value: {{ .Values.redis.namespaces.<namespace> }}
```
## Redis 变量参考
Redis 运行时变量会在部署过程中注入到 `values.yaml` 中。这些变量由系统统一管理,用户无法自行修改。
| 变量 | 类型 | 说明 |
|--|--|--|
| `.Values.redis.host` | String | Redis 主机地址。 |
| `.Values.redis.port` | Number | Redis 端口。 |
| `.Values.redis.password`| String | Redis 密码。 |
| `.Values.redis.namespaces` | Map<String, String> | 请求的命名空间集合,按名称为键。<br>例如,请求 `app_ns`,可通过 `.Values.redis.namespaces.app_ns`获取对应值。 |