Databases

Redis with Spring Boot, Laravel, Django and Node.js: caching, sessions and queues on Cloud Ninza

3 min read By Cloud Ninza

Most modern frameworks expect Redis for cache, sessions and queues. Here is how to connect each one to the private Redis included with Cloud Ninza Growth, Business and Pro plans.

In short On Cloud Ninza Growth, Business and Pro plans, turn on Redis in the dashboard (Databases → Redis) and press “Add these settings to my app”: REDIS_URL, REDIS_HOST, REDIS_PORT, REDIS_PASSWORD and REDIS_SOCKET are added to your Node.js, Python or Java app’s environment, plus SPRING_DATA_REDIS_* for Spring Boot. Spring Boot with spring-boot-starter-data-redis then needs no extra configuration; Django, Flask, FastAPI and Node.js read REDIS_URL; Laravel uses REDIS_HOST, REDIS_PORT and REDIS_PASSWORD in .env with the installed phpredis extension.

Before you start

  • Your plan: Growth (64 MB), Business (128 MB) or Pro (256 MB) of PHP, Node.js, Python or Java hosting.
  • Dashboard → Databases → Redis → Turn Redis on. The page shows host 127.0.0.1, port, password, a Unix socket path and REDIS_URL.
  • For Node.js, Python and Java apps, press “Add these settings to my app” — the variables are added and the app restarts once.
  • Only your hosting account can connect; the password is always required.

Spring Boot

Add spring-boot-starter-data-redis (and spring-boot-starter-cache for @Cacheable). Spring Boot’s relaxed binding reads SPRING_DATA_REDIS_HOST, SPRING_DATA_REDIS_PORT and SPRING_DATA_REDIS_PASSWORD from the environment, so after “Add these settings to my app” no properties are needed. Add @EnableCaching to a configuration class and spring.cache.type=redis; set a default TTL with spring.cache.redis.time-to-live=10m.

Sessions: add spring-session-data-redis and set spring.session.store-type=redis (Spring Boot 3 detects it automatically). Lettuce, the default client, connects over TCP to 127.0.0.1 and the port shown.

Laravel and PHP

The phpredis extension is installed on every PHP version. In .env set REDIS_CLIENT=phpredis, REDIS_HOST=127.0.0.1, REDIS_PORT and REDIS_PASSWORD from the Redis page, then CACHE_STORE=redis, SESSION_DRIVER=redis and QUEUE_CONNECTION=redis, and run php artisan config:cache. Queue workers can run from a cron job (php artisan queue:work --stop-when-empty every minute) on our hosting.

Plain PHP: $r = new Redis(); $r->connect('127.0.0.1', PORT); $r->auth(PASSWORD);.

Django, Flask and FastAPI

Django 4+ has a built-in Redis cache backend: CACHES = {"default": {"BACKEND": "django.core.cache.backends.redis.RedisCache", "LOCATION": os.environ["REDIS_URL"]}}. Store sessions in it with SESSION_ENGINE = "django.contrib.sessions.backends.cache" (or cached_db to keep a database copy).

Flask and FastAPI: install redis (redis-py) and create a client with redis.Redis.from_url(os.environ["REDIS_URL"]); the asyncio client is redis.asyncio.from_url. Celery can use REDIS_URL as its broker for light background jobs.

Node.js (Express, NestJS, Next.js)

ioredis or node-redis: new Redis(process.env.REDIS_URL), or the Unix socket for the lowest latency: new Redis({ path: process.env.REDIS_SOCKET, password: process.env.REDIS_PASSWORD }). Sessions with connect-redis; NestJS caching with the cache-manager Redis store; job queues with BullMQ, which needs maxRetriesPerRequest: null on its connection.

Next.js: use Redis from route handlers or server actions for rate limits and cached API results; the incremental cache can stay on disk.

Good key design and limits

When memory is full, the least recently used keys are removed (allkeys-lru). Watch evictions on the dashboard’s Redis page; frequent evictions mean you need a larger plan or shorter TTLs.

PracticeWhy
Prefix keys by app and type (shop:product:42)Easy to find, flush or measure one kind of data
Always set a TTL on cache keysStale data expires on its own
Keep values small (under a few hundred KB)Large values slow every reader and fill memory
Do not use KEYS * in productionIt scans everything; use SCAN
Keep the source of truth in your databaseRedis is a cache and evicts when full

Security on shared hosting

Each Cloud Ninza hosting account runs its own Redis as its own Linux user, inside the account’s memory limit. Connections from other accounts are refused by the server firewall and the socket’s permissions, the internet cannot reach it, a password is always required, and administrative commands such as CONFIG and MODULE are disabled. Snapshots are saved in your home folder and included in the twice-daily backups.

Key takeaways

The short version, for anyone skimming:

  • Turn Redis on, press “Add these settings to my app”, and most frameworks connect with no code changes.
  • Spring Boot reads SPRING_DATA_REDIS_*; Django, Flask, FastAPI and Node.js read REDIS_URL; Laravel uses .env and phpredis.
  • Use it for cache, sessions, rate limits and light queues; keep important data in your database.
  • Prefix keys, set TTLs and watch evictions.
  • Included with Growth, Business and Pro plans of PHP, Node.js, Python and Java hosting.
Host it with us

Java Hosting

Java hosting on cloud servers in India from ₹299 a month, billed yearly. Backups twice a day (12 AM and 12 PM), last 30 days kept — restore any date yourself from your dashboard, or make your own backup any time · Spam protection: hourly and daily email sending limits per project, and automatic pausing of spam-like sending, keep your domain and our mail servers trusted · OpenJDK 11, 17, 21 or 25.

Ready when you are

Hosting from ₹149 a month on servers in India

WordPress, static HTML, PHP, Node.js, Python and Java plans with free SSL and your choice of version. Create your account, pick a plan and pay by UPI, card or netbanking; your hosting is created automatically and you get your login by email, usually within minutes.

Questions

Questions on this topic

How do I connect Spring Boot to Redis on Cloud Ninza?

Turn Redis on, press “Add these settings to my app”, and add spring-boot-starter-data-redis. Spring Boot reads SPRING_DATA_REDIS_HOST, PORT and PASSWORD from the environment automatically.

Can I run Laravel queues with Redis here?

Yes, set QUEUE_CONNECTION=redis and run the worker from a cron job with --stop-when-empty. For heavy, always-on queues use a cloud server.

Does Django’s built-in Redis cache work?

Yes, use django.core.cache.backends.redis.RedisCache with LOCATION set to REDIS_URL.

Can BullMQ run on Cloud Ninza hosting?

Yes, for light queues. Use the REDIS_URL connection with maxRetriesPerRequest: null.

Is it real Redis?

It is Valkey 7.2, the open-source, Redis-compatible continuation of Redis; Redis clients and libraries work unchanged.

Can other customers reach my Redis?

No. It runs as your account, other accounts are refused by the firewall and file permissions, and a password is always required.

What if I need more than 256 MB?

Choose a Cloud Ninza cloud server for gigabytes of Redis or heavy queues; ask for a quote.

Does Redis restart with my app?

It runs separately and keeps running when your app restarts. It stops only when the project is suspended or you turn it off.