Caching Application Data Using Redis Labs Redis

You can use Redis Labs Cloud to cache application data. Redis Cloud is a fully-managed service offering a variety of options for running Redis.


Redis Labs offers a free tier that provides 30 MB of storage.

Setting up

To use Redis by Redis Labs:

  1. Sign up for a Redis Labs Cloud account.
  2. Create a Redis Database using Redis Cloud. Be sure to specify GCE/us-central1 as the Cloud for the lowest latency. Specify a strong password as your Redis instance will be publicly accessible.
  3. Note the Endpoint for the database.

Installing a Redis client library

We recommend using the redis Python library for accessing your Redis instance.

Include redis in your requirements.txt file:


If running locally, install your dependencies using pip:

pip install -r requirements.txt

Connecting to Redis by Redis Labs

Configure environment variables in your app.yaml with the endpoint and password for your Redis by Redis Labs database:
    REDIS_HOST: your-redis-host
    REDIS_PORT: your-redis-port
    REDIS_PASSWORD: your-redis-password
Use the environment variables in your application code to configure a Redis client:
redis_host = os.environ.get('REDIS_HOST', 'localhost')
redis_port = int(os.environ.get('REDIS_PORT', 6379))
redis_password = os.environ.get('REDIS_PASSWORD', None)
redis_client = redis.StrictRedis(
    host=redis_host, port=redis_port, password=redis_password)

Testing Redis locally

If you are testing your app locally, you can still connect to your the Redis Labs Redis database. However, you might want to run a local instance of Redis to avoid interacting with production data.

Follow the directions in the Redis documentation to install and run Redis locally. Note that it currently isn't possible to run Redis locally on Windows.

Was this page helpful? Let us know how we did:

Send feedback about...

App Engine flexible environment for Python docs