I’m trying to connect my Flask app running on Google Cloud Run to a Google Cloud Memorystore Redis instance, but I keep getting a timeout error. Both Cloud Run and Redis are in the same region and VPC network, and everything seems configured correctly, but it still won’t connect.
Setup Details:
- Redis IP: 10.x.x.x
- Cloud Run Region: europe-west4
- Redis Region: europe-west4-a
- VPC Connector: default-connector (attached to Cloud Run)
Firewall Rules:
- Ingress allows traffic to Redis on port 6379 from the VPC connector IP range (100.8.0.0/28)
- Egress rules allow outgoing traffic from Cloud Run to Redis
What I’ve Tried:
- Checked VPC Flow logs, Enabled flow logs but haven’t seen anything indicating network traffic from Cloud Run to Redis
- Checked Firewall logs, The logs show no blocks, and the rules should allow Redis traffic
Simple script I use to test, right now it always returns “Error connecting to Redis: timeout connecting to server”
from flask import Flask
import redis
app = Flask(__name__)
@app.route("/")
def test_redis():
try:
redis_host = "10.x.x.x"
redis_port = int(6379)
r = redis.Redis(
host=redis_host, port=redis_port, db=0, socket_connect_timeout=20
)
r.ping()
return "Successfully connected to Redis!"
except Exception as e:
return f"Error connecting to Redis: {e}", 500
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
Any suggestion or help is greatly appreciated, as I’ve tried any resource I could find and to me it feels like I’ve done everything the same.
3