Back to Directory
How to Monitor Recent

How to Monitor Redis & Check Cache Connection Health

SAuthor

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

  1. Log in to your Pingzo Dashboard.
  2. Create a new HTTP/HTTPS Monitor pointing to your endpoint (e.g. https://your-api.com/api/healthz/cache).
  3. Set checking intervals to 1 minute and set up WhatsApp Alerts to page your SRE team immediately if the route returns an HTTP 500 error 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

pz-console
// CLI Ping Test
$redis-cli ping
// ioredis Client Ping
const Redis = require('ioredis');
const redis = new Redis(process.env.REDIS_URL);
const status = await redis.ping(); // Returns 'PONG'
[pingzo-agent] monitoring active: Redis
[pingzo-agent] status: 200 OK | latency: 85ms
DevOps Uptime Check

Uptime monitoring built for Redis developers

Configure HTTP health routes, inspect SSL status, and track cron workers from our console dashboard. Get direct texts on WhatsApp.

Start Monitoring Free