diff --git a/.devcontainer/README.md b/.devcontainer/README.md index 96c010b0c99e..5ed5e5b240e0 100644 --- a/.devcontainer/README.md +++ b/.devcontainer/README.md @@ -8,7 +8,7 @@ Currently, the devcontainer setup leverages docker compose to setup two containers: 1. The main development container which contains: - - Node and Python + - Node, Python, and Redis 2. [Datastore Emulator](https://cloud.google.com/datastore/docs/tools/datastore-emulator) 3. [Datastore Emulator viewer](https://github.com/remko/dsadmin) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index ef4db7c2a8e2..c53296eea78a 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -16,3 +16,7 @@ services: environment: DATASTORE_PROJECT_ID: cr-status-staging DATASTORE_EMULATOR_HOST: localhost:15606 + REDISHOST: redis + + redis: + image: redis:latest diff --git a/README.md b/README.md index 704929c5f11d..3f37c92e7bbd 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ For a one-click setup that leverages devcontainers, check out the devcontainer 1. node and npm. 1. Gulp: `npm install --global gulp-cli` 1. Python virtual environment: `sudo apt install python3.11-venv` + 1. Redis: [installation guide](https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/) 1. We recommend using an older node version, e.g. node 18 1. Use `node -v` to check the default node version 2. `nvm use 18` to switch to node 18 diff --git a/framework/rediscache.py b/framework/rediscache.py index 0e38482cce45..3b90e7d27828 100644 --- a/framework/rediscache.py +++ b/framework/rediscache.py @@ -32,13 +32,23 @@ if settings.UNIT_TEST_MODE: redis_client = fakeredis.FakeStrictRedis() -elif settings.STAGING or settings.PROD: +elif settings.STAGING or settings.PROD or settings.DEV_MODE: # Create a Redis client. redis_host = os.environ.get('REDISHOST', 'localhost') redis_port = int(os.environ.get('REDISPORT', 6379)) redis_client = redis.Redis(host=redis_host, port=redis_port, health_check_interval=30, socket_keepalive=True, retry_on_timeout=True, retry=Retry(ExponentialBackoff(cap=5, base=1), 5)) +# Try pinging client to ensure connection +try: + redis_client.ping() +except redis.ConnectionError: + # Only allow non-caching to happen during DEV_MODE + if not settings.DEV_MODE: + raise + redis_client = None + logging.info("Redis server not installed on machine, not using caching") + gae_version = None if settings.UNIT_TEST_MODE: # gae_version prefix for testing.