1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# redis-server.yml
redis:
image: redis:alpine
restart: always
command: redis-server --port 6379
container_name: redis
volumes:
- ./data/redis/data:/data
- ./data/redis/conf/redis.conf:/usr/local/etc/redis/redis.conf
- ./data/redis/acl/users.acl:/etc/redis/users.acl
command: redis-server /usr/local/etc/redis/redis.conf
labels:
- "name=redis"
- "mode=standalone"
ports:
- 6379:6379
1
2
3
4
docker exec -it redis redis-cli
ping
key *
SET foot foo
1
CONNECT_FAIL: Redis server did not respond to PING message.
networks
를 추가
https://docs.docker.com/compose/networking/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
LOCAL_REDIS_URL = "redis://redis:6379" # docker service name
logger = logging.getLogger(__name__)
app = FastAPI(title='vagazine')
@app.on_event("startup")
def startup():
redis_cache = FastApiRedisCache()
redis_cache.init(
host_url=os.environ.get("REDIS_URL", LOCAL_REDIS_URL),
prefix="myapi-cache",
response_header="X-MyAPI-Cache",
ignore_arg_types=[Request, Response, Session]
)
@app.get("/items")
@cache(expire=30)
def read_items():
return {}
1
*229 connect() failed (111: Connection refused) while connecting to upstream