-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add module of web, support crud of config server.
- Loading branch information
bigtutu
authored and
bigtutu
committed
Dec 9, 2024
1 parent
8f0ae4c
commit 8a10238
Showing
26 changed files
with
1,195 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import asyncio | ||
from redis_config_client import config_client | ||
|
||
# 客户端快速开始示例: | ||
async def test(): | ||
await config_client.start() | ||
await asyncio.sleep(6) # 等待足够的时间让配置刷新完成 | ||
|
||
cur_config_group = config_client.get_config_group() | ||
test_val = config_client.get_config("test_key") | ||
|
||
print(f"客户端当前配置组信息为:{cur_config_group}") | ||
print(f"客户端当前配置'test_key'的值为:{test_val}") | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(test()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from contextlib import asynccontextmanager | ||
import uvicorn | ||
from fastapi import FastAPI | ||
from redis_config_client import config_client | ||
|
||
# FastAPI 集成 redis_config_client 示例: | ||
# 1. 绑定 config_client.start() 到 FastAPI 的 lifespan,在应用启动时初始化配置客户端。 | ||
# 2. 在 config_client.start() 成功启动后,项目的任何地方都可以直接调用 | ||
# redis_config_client.ConfigClient.get_config() 方法获取配置。 | ||
|
||
@asynccontextmanager | ||
async def lifespan(app: FastAPI): | ||
# 启动配置客户端 | ||
await config_client.start() | ||
yield | ||
|
||
# 创建 FastAPI 应用实例,并绑定 lifespan 函数 | ||
app = FastAPI(lifespan=lifespan) | ||
|
||
# 示例路由,您可以根据需要添加更多路由和功能 | ||
@app.get("/") | ||
async def read_root(): | ||
return { | ||
"code": "200", | ||
"message": "Hello, Redis Config Center!", | ||
"data": config_client.get_config_group() | ||
} | ||
|
||
if __name__ == "__main__": | ||
# 使用 uvicorn 运行 FastAPI 应用 | ||
# 可直接访问 http://127.0.0.1:8089/ 查看当前最新配置 | ||
uvicorn.run(app, host="127.0.0.1", port=8089) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import asyncio | ||
from redis_config_server import config_server, ConfigGroup | ||
|
||
# 服务端快速开始示例: | ||
async def test(): | ||
await config_server.insert_config_group( | ||
ConfigGroup(group_name="default", group_version=1, config_dict={"key1": "value1"})) | ||
# ... 插入其他配置组 ... | ||
|
||
print(await config_server.get_config_group("default")) | ||
# ... 获取其他配置组 ... | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(test()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
pydantic==2.7.4 | ||
pydantic_core==2.18.4 | ||
libvalkey==4.0.0 | ||
valkey==6.0.2 | ||
valkey==6.0.2 | ||
|
||
fastapi==0.111.0 | ||
fastapi-cli==0.0.4 |
Oops, something went wrong.