How to Monitor Redis Uptime & Cache Health
Redis is an extremely fast, in-memory key-value database widely used for caching sessions, message queuing, and pub/sub brokers. Because of its in-memory nature, Redis is sensitive to out-of-memory (OOM) errors and connection pool exhaustion. If Redis goes down, your session handler fails, page loads slow down, and background jobs halt.
Since caching nodes reside securely in private cloud virtual networks behind firewalls, public checking nodes cannot access them directly. This guide details how to monitor Redis cache connectivity and configure alert notifications before your memory limits are exceeded.
Method 1: Set Up an Application-Level Cache Health Endpoint
The most secure and reliable pattern to verify Redis health is to probe it via an internal health route exposed by your application API. This route runs a light command (like PING) against your Redis client.
Node.js (Express & ioredis) Cache Health Route Example
Implement a health checker route in your app:
const express = require('express');
const Redis = require('ioredis');
const app = express();
const redis = new Redis(process.env.REDIS_URL, {
connectTimeout: 2000, // Fail fast if Redis server is unresponsive
maxRetriesPerRequest: 1
});
app.get('/api/healthz/cache', async (req, res) => {
try {
// Execute a fast Redis PING command
const response = await redis.ping();
if (response === 'PONG') {
res.status(200).json({ status: 'OK', cache: 'connected' });
} else {
res.status(500).json({ status: 'ERROR', message: 'Unexpected ping response' });
}
} catch (err) {
console.error('Redis cache health check failed:', err);
res.status(500).json({ status: 'ERROR', message: 'Redis is offline' });
}
});
app.listen(3000);
Configure Pingzo to Probe the Cache Health Endpoint
- Log in to your Pingzo Dashboard.
- Create a new HTTP/HTTPS Monitor pointing to your endpoint (e.g.
https://your-api.com/api/healthz/cache). - Set checking intervals to 1 minute and set up WhatsApp Alerts to page your SRE team immediately if the route returns an HTTP
500error or times out.
Method 2: Push Monitoring (Heartbeat) for Redis Backups & Syncs
If you run recurring tasks that backup your Redis database (SAVE or BGSAVE exports) or sync data structures, use Heartbeat (Push) Monitoring in Pingzo:
- Configure a Heartbeat Monitor on Pingzo.
- Append a curl ping at the end of your database backup script:
#!/bin/bash
redis-cli save && \
curl -fsS https://ping.pingzoapp.com/ping/your-unique-heartbeat-id
If Redis freezes or runs out of memory, the backup fails, the webhook ping is skipped, and Pingzo pages you.
Key Redis Metrics to Monitor
Ensure your internal APM panels track these metrics:
- used_memory: The total number of bytes allocated by Redis. Set alerts when this nears your maximum memory limit to prevent memory eviction crashes.
- connected_clients: The number of active client connections. Track this to ensure connection pooling works correctly and clients do not leak.
- evicted_keys: High keys eviction counts indicate your cache size is too small for active traffic.
Summarize with AI
Instantly generate a summary of this page using your favorite LLM