Skip to content

Commit

Permalink
optimization: redis sentinel 模式支持配置 redis sentinel 独立密码
Browse files Browse the repository at this point in the history
  • Loading branch information
homholueng committed Aug 3, 2020
1 parent 350d656 commit 2b68420
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions dev_log/dev/homholueng_202008031045.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
improvement:
- " redis sentinel 模式支持配置 redis sentinel 独立密码"
31 changes: 31 additions & 0 deletions docs/features/redis_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
标准运维能够使用以下几种部署模式的 redis 服务,对应模式需要的配置如下:

## 单实例模式

单实例模式,需要配置以下环境变量

- BKAPP_REDIS_MODE:`single`
- BKAPP_REDIS_HOST:redis 服务 host
- BKAPP_REDIS_PORT:redis 服务端口
- BKAPP_REDIS_PASSWORD(非必须):redis 访问密码
- BKAPP_REDIS_DB(非必须):redis db

## 集群模式

需要配置以下环境变量

- BKAPP_REDIS_MODE:`cluster`
- BKAPP_REDIS_HOST:redis 集群中任意一台节点的 host
- BKAPP_REDIS_PORT:redis 集群中任意一台节点的端口
- BKAPP_REDIS_PASSWORD(非必须):redis 访问密码

## Sentinel 模式

需要配置以下环境变量

- BKAPP_REDIS_MODE:replication
- BKAPP_REDIS_HOST:sentinel host,支持配置多 sentinel,host 间以 `,` 分隔
- BKAPP_REDIS_PORT:sentinel port,支持配置多 sentinel,port 间以 `,` 分隔,port 数量与 sentinel 数量必须保持一致
- BKAPP_REDIS_PASSWORD(非必须):redis 访问密码
- BKAPP_REDIS_SERVICE_NAME(非必须):redis 集群 master service name
- BKAPP_REDIS_SENTINEL_PASSWORD(非必填):redis sentinel 密码,若不填,则使用 redis 的密码
2 changes: 2 additions & 0 deletions gcloud/core/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def ready(self):
"service_name": EnvironmentVariables.objects.get_var("BKAPP_REDIS_SERVICE_NAME"),
"mode": EnvironmentVariables.objects.get_var("BKAPP_REDIS_MODE"),
"db": EnvironmentVariables.objects.get_var("BKAPP_REDIS_DB"),
"sentinel_password": EnvironmentVariables.objects.get_var("BKAPP_REDIS_SENTINEL_PASSWORD"),
}
except Exception:
logger.warning(traceback.format_exc())
Expand All @@ -51,4 +52,5 @@ def ready(self):
"service_name": os.getenv("BKAPP_REDIS_SERVICE_NAME"),
"mode": os.getenv("BKAPP_REDIS_MODE"),
"db": os.getenv("BKAPP_REDIS_DB"),
"sentinel_password": os.getenv("BKAPP_REDIS_SENTINEL_PASSWORD"),
}
5 changes: 4 additions & 1 deletion pipeline/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@


def get_client_through_sentinel():
kwargs = {}
kwargs = {"sentinel_kwargs": {}}
sentinel_pwd = settings.REDIS.get("sentinel_password")
if sentinel_pwd:
kwargs["sentinel_kwargs"]["password"] = sentinel_pwd
if "password" in settings.REDIS:
kwargs["password"] = settings.REDIS["password"]
host = settings.REDIS["host"]
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
- [变量引擎](docs/features/variables_engine.md)
- [Tag使用和开发说明](docs/develop/tag_usage_dev.md)
- [移动端使用说明](docs/features/mobile.md)
- [redis 部署模式支持](docs/features/redis_usage.md)


## Version plan
- [版本日志](docs/release.md)
Expand Down

0 comments on commit 2b68420

Please sign in to comment.