Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional Redis setup for development environment #4515

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ services:
environment:
DATASTORE_PROJECT_ID: cr-status-staging
DATASTORE_EMULATOR_HOST: localhost:15606
REDISHOST: redis

redis:
image: redis:latest
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion framework/rediscache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down