Skip to content

Node.js on VIP

Integrating Redis

Redis is an optional add-on for Node.js applications on the WordPress VIP Platform. To enable Redis for a Node.js application, create a VIP Support request.

Connecting to Redis

Once VIP has enabled Redis, additional configurations are needed in order for the Node.js application to interact with it.

These environment variables will be defined by VIP:

  • VIP_REDIS_PRIMARY: The primary Redis endpoint, represented by an IP address and port separated by a colon. Example: "127.0.0.1:1234".
  • VIP_REDIS_PASSWORD: The password value, identical for the primary instance and all replicas.

The above environment variables can be accessed with process.env (e.g., process.env.VIP_REDIS_PRIMARY). Depending on which method is chosen to connect to Redis, these values may need to be parsed to extract the IP address and port.

The ioredis package is a library commonly used for interacting with Redis, and the following code example code shows how it can be used to create a Redis client (redisClient ) using the VIP_REDIS_PRIMARY and VIP_REDIS_PASSWORD environment variables:

const Redis = require( 'ioredis' );
const [ host, port ] = process.env.VIP_REDIS_PRIMARY.split( ':' );
const password = process.env.VIP_REDIS_PASSWORD;
const redisClient = new Redis( { host, port, password } );

Data ephemerality

Redis is not guaranteed to be persistent and should be considered an ephemeral cache store. Data stored in Redis is not backed up and cannot not be restored to a previous state.

If an application’s performance could suffer during a Redis cold start, consider writing and maintaining a script that populates the cache, and develop a strategy for running it against the application.

Error handling

It is strongly recommended to configure an application to catch errors, and to fall back gracefully in case Redis is ever unavailable. Redis is very reliable, but there may be brief moments when it is unavailable if configuration or security updates are performed by VIP.

Disabled operations

The Redis operations EVALEVALSHA, and SCRIPT can cause severe performance issues and are disabled by default. It is possible for these operations to be enabled if absolutely necessary by creating a VIP Support request.

Last updated: April 21, 2022