This example demonstrates how to integrate a Redis Cluster Cache with a Next.js application.
- Debian-based OS: Ensure your operating system is Debian-based (e.g., Ubuntu, Debian).
- Docker: Ensure Docker is installed on your machine.
- Node.js: Ensure Node.js (and npm) is installed on your machine.
MacOS and Windows users can use Dev Containers to run the example in a containerized environment. This project includes a devcontainer.json
file that defines the container image and the necessary dependencies.
To start Redis locally, run:
docker-compose up -d
Install the necessary Next.js dependencies:
npm i
Build the Next.js application. Note that the custom Redis cache handler will not be used during the build process:
npm run build
Start the Next.js application:
npm run start
Navigate to the local homepage in your browser:
Then navigate through the different timezones to see the cache in action.
To remove logs, edit the package.json file by removing NEXT_PRIVATE_DEBUG_CACHE=1
.
Redis data will be stored in redis/node-X/data
.
To flush all data from the Redis cluster, use the following commands:
Enter the Docker container:
docker exec -it cache-handler-redis-cluster-example-redis-1-1 /bin/bash
Flush all Redis nodes:
redis-cli --cluster call --cluster-only-masters 172.38.0.11:6379 FLUSHALL