🎉 Version 1.8.0 is out! Use shared cache for the Next.js Pages API routes and getServerSideProps with neshClassicCache
Usage guidesOpt out the cache on Build

Building the App Without Redis Cache Connection

There are scenarios, especially during deployment, where your Redis server may not be immediately available. This can occur when the Redis server and your app are deployed simultaneously. In such cases, it’s important to configure your build process to handle the absence of the Redis server. Here’s how you can adapt your setup to build the app without requiring an active connection to the Redis server:

Configuration Steps

  1. Modify the cache-handler.mjs File: Adjust the onCreation method in your cache-handler.mjs file to conditionally connect to the Redis server. The modified code should look like this:

    cache-handler.mjs
    CacheHandler.onCreation(async () => {
      let handler;
     
      if (process.env.REDIS_AVAILABLE) {
        await client.connect();
     
        handler = await createRedisHandler({
          client,
        });
      }
     
      return {
        handlers: [handler],
      };
    });
  2. Environment Variable Check: The process.env.REDIS_AVAILABLE environment variable is used to determine if the server has already started. This ensures that the Redis client attempts a connection only when the server is up and running. You may use a different environment variable or a more sophisticated check based on your deployment setup.