Menu

Redis Integration

Redis is a common infrastructure component in commercial projects, mainly used for caching, rate limiting, session storage, and other business-logic-related features.

The NEXTY.DEV boilerplate wraps Redis with a multi-provider abstraction and supports two modes out of the box:

  • Upstash: REST API-based serverless Redis, compatible with Edge / Cloudflare Workers runtimes.
  • ioredis: TCP-based self-hosted Redis, suitable for Node.js servers or Vercel deployments.

Select the provider via the DEFAULT_REDIS_PROVIDER environment variable (defaults to upstash). When the credentials for the selected provider are not configured, related features gracefully degrade without affecting other business logic.

Good to know The boilerplate includes a rate limiter example in the newsletter subscription feature that automatically decides whether to enable rate limiting based on your Redis configuration.

Select a Provider

ProviderUse CaseEnvironment Variables
upstash (default)Serverless deployments, Edge / Cloudflare WorkersUPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN
ioredisNode.js servers, Vercel, self-hosted / Coolify RedisREDIS_URL

Upstash Configuration

  1. Visit Upstash and register an account with your email

  2. Go to the Dashboard page and click the Create database button

Create database
Create database
Create database
  1. Enter the database details page, and in the REST API module copy UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN to your environment variables
upstash api
  1. Make sure DEFAULT_REDIS_PROVIDER=upstash or leave it unset (the default is upstash)

Self-Hosted Redis (ioredis) Configuration

  1. Prepare a Redis instance. For local development use redis://localhost:6379; for production you can use a managed Redis such as Coolify. See Coolify Redis deployment.

  2. Write the connection URL to REDIS_URL and set the provider:

DEFAULT_REDIS_PROVIDER=ioredis
REDIS_URL=redis://localhost:6379

Note ioredis depends on the Node.js net module, so it does not work in Edge or Cloudflare Workers. Use the Upstash provider for those runtimes.

Verification

Now you can try submitting a newsletter subscription in the page Footer again:

  • If using Upstash, check the Data Browser page in Upstash Redis. If there's new data, it means the subscription rate limiter is working.
  • If using ioredis, verify the corresponding key with redis-cli or RedisInsight.
upstash data browser

Secondary Development

Business code should import from lib/redis:

import { redis, checkRateLimit, getClientIPFromRequest } from "@/lib/redis";
  • redis: unified Redis client providing get, set, incr, sadd, srem, sismember, etc.
  • checkRateLimit: performs rate-limit checks based on the active provider (sliding window for Upstash, fixed window for ioredis).
  • getClientIPFromRequest / getClientIPFromHeaders: retrieves the client IP.

When you need direct provider-native capabilities, export upstashRedis or ioRedis.