# seatools-starter-redis **Repository Path**: seatools-py/seatools-starter-redis ## Basic Information - **Project Name**: seatools-starter-redis - **Description**: seatools ioc redis 启动器 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-10 - **Last Updated**: 2025-05-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: Python, ioc, Spring, starter ## README # Seatools-starter-redis seatools ioc 的 redis 启动器 ## 仓库地址: 1. https://github.com/seatools-py/seatools-starter-redis 2. https://gitee.com/seatools-py/seatools-starter-redis ## 使用指南 1. 安装, `poetry add seatools-starter-redis` 2. 配置文件`config/application.yml`配置如下: ```yaml # seatools 配置 seatools: # redis 配置 redis: host: localhost port: 6379 password: 123456 database: 0 is_async: false # 是否异步, 默认false, 若为true, 则bean实例为redis.asyncio.Redis类型 # redis.Redis.from_url的额外参数 config: # 示例: # 响应自动解码配置 decode_responses: true redis_async: host: localhost port: 6379 password: 123456 database: 0 is_async: true # 是否异步, 默认false, 若为true, 则bean实例为redis.asyncio.Redis类型 # redis.Redis.from_url的额外参数 config: # 示例: # 响应自动解码配置 decode_responses: true ``` 3. 使用示例 ```python from seatools.ioc import run, Autowired from redis import Redis # 启动ioc run(scan_package_names=[], config='./config') # ------- 同步 ------------ # 获取redis.Redis实例 client = Autowired(cls=Redis) client.set(...) client.get(...) # ----------------------- # ------- 异步 ----------- from redis.asyncio import Redis as AsyncRedis client_async = Autowired(cls=AsyncRedis) async def get_async(key: str): async with client_async.pipeline() as pipe: await pipe.get(key) return (await pipe.execute())[0] import asyncio asyncio.run(get_async("xxx")) # ------------------------ ```