When you run FastAPI and redis in separate containers the host of the redis is not localhost
anymore for other containers instead you should get the host by running docker inspect <redis_container_name>
there you will find IPAdress which is "IPAddress": "172.17.0.2"
in my case.
You need to configure you fast api to connect to this host by replacing the localhost
with IPAddress.