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 package.

To install:

npm install --save redis

Connecting to Redis by Redis Labs

For Node.js, nconf can help you handle configuration settings including your connection settings.

Create a keys.json file in your application's root directory and update the configuration with your Redis database's setting:

  "redisHost": [YOUR_REDIS_HOSTNAME],
  "redisPort": [YOUR_REDIS_PORT_NUMBER],

Use nconf to load your configuration and redis to create a Redis client:

// Connect to a redis server provisioned over at
// Redis Labs. See the README for more info.
const client = redis
    nconf.get('redisPort') || '6379',
    nconf.get('redisHost') || '',
      auth_pass: nconf.get('redisKey'),
      return_buffers: true,
  .on('error', err => console.error('ERR:REDIS:', err));

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.

Оцените, насколько информация на этой странице была вам полезна:

Оставить отзыв о...

Текущей странице
App Engine flexible environment for Node.js docs