RedisCLI icon
Docker icon
OutputValues icon
Log icon
If icon
SlackIncomingWebhook icon
LoopUntil icon
Fail icon
Schedule icon

Redis Persistence Guard

Detect Redis instances with no persistence, failed BGSAVE or AOF writes and stale snapshots, alert Slack, enable persistence and verify with INFO.

Categories
DataInfrastructure

Redis is often used as more than a cache: session stores, rate limiters, job queues, feature flags. Then the persistence settings matter. They are easy to get wrong:

  • an image started with --save "";
  • appendonly left at its default no;
  • a disk that filled up so BGSAVE has been failing for days.

Nothing complains until the instance restarts, and every key is gone.

This blueprint reads INFO persistence and the save configuration with redis-cli and checks them against the persistence you require. It alerts Slack when Redis is not persisting as required. It can also turn persistence on with CONFIG SET, force a BGSAVE, poll until it completes and read INFO again to verify.

This blueprint was created by zkasuran.

Findings

Finding Rule
NO_PERSISTENCE save is empty and appendonly is off: every key is lost on restart
AOF_REQUIRED_OFF / RDB_REQUIRED_OFF The required mechanism is disabled
BGSAVE_FAILED rdb_last_bgsave_status is not ok, usually a full disk or a permission problem
AOF_WRITE_FAILED aof_last_write_status is not ok
STALE_SNAPSHOT RDB is on, but the last save is older than max_snapshot_age_minutes while keys have changed

How it works

  1. info and save_config (io.kestra.plugin.redis.cli.RedisCLI, read-only) run INFO persistence and CONFIG GET save. state parses them.
  2. findings checks them in one jq expression. summary logs the result every run.
  3. route (io.kestra.plugin.core.flow.If):
    • persisting: logs it.
    • findings: alert posts to Slack.
      • remediate_gate runs only when auto_remediate is true and dry_run is false.
      • enable_aof and enable_rdb run CONFIG SET appendonly yes and CONFIG SET save "<policy>" only where needed, then bgsave takes a snapshot of what is already in memory.
      • wait_for_save (io.kestra.plugin.core.flow.LoopUntil) polls INFO every 2 seconds until the save has finished with no unsaved change.
      • verify_result reads INFO and save again, and fails if anything is still off.
  4. errors alerts Slack when the flow fails, for example on an unreachable host.

Each RedisCLI task runs a single command. CONFIG SET lasts until the next restart: the final log reminds you to run CONFIG REWRITE or update redis.conf.

What you get

  • A persistence check that reads Redis itself, not the config file you think it uses.
  • Findings for no persistence, a disabled required mechanism, failed saves and stale snapshots.
  • A remediation that enables persistence, forces a snapshot, waits for it and verifies it.

Who it's for

  • Teams that use Redis for sessions, queues, rate limits or feature flags, where losing the data is an outage.
  • Platform teams running many Redis instances started from different images and charts.
  • Teams evaluating the Redis plugin who want an example of RedisCLI driving checks and changes.

Why orchestrate this with Kestra

INFO persistence answers the question for one instance at one moment. Kestra runs it on a schedule, turns the answer into a Slack alert, gates the change, polls the background save with LoopUntil until it is really on disk, and keeps a history that shows when an instance stopped persisting.

Tested end to end

On Kestra 2.0.5 OSS against Redis 7 containers started with and without persistence, with a local HTTP sink standing in for Slack.

Run Target Result
1 500 keys, --save "", --appendonly no NO_PERSISTENCE, AOF_REQUIRED_OFF, RDB_REQUIRED_OFF. Alert sent
2 same, dry run Same findings, CONFIG GET appendonly still no
3 same, remediate AOF and RDB enabled, BGSAVE awaited and verified. After docker restart, all 520 keys are back
4 control: no persistence, not remediated After docker restart, 0 keys
5 started with AOF and RDB Persisting as required, no alert
6 RDB, a write 1 minute after the last save, max_snapshot_age_minutes: 0 STALE_SNAPSHOT
7 unknown host errors alert sent

Prerequisites

  • A Redis instance reachable from the Docker containers the RedisCLI tasks start. CONFIG must not be renamed or disabled for remediation.
  • Local testing: docker run -d --name redis --network mynet redis:7-alpine redis-server --save "" --appendonly no.
  • For a password or ACL user, add password: "{{ secret('REDIS_PASSWORD') }}" (and username) to each RedisCLI task.

Secrets

  • SLACK_WEBHOOK_URL: used by alert and the errors block. In Kestra OSS, provide it as the base64-encoded environment variable SECRET_SLACK_WEBHOOK_URL.

Inputs

Input Default Purpose
host / port localhost / 6379 Redis instance
required RDB_AND_AOF RDB, AOF or both
rdb_save_policy 3600 1 300 100 60 10000 Applied when RDB is required but off
max_snapshot_age_minutes 120 Stale snapshot threshold
auto_remediate false Allow CONFIG SET and BGSAVE
dry_run true Must be false for a change to apply
network empty Docker network for the redis-cli containers

The every_15_minutes trigger is shipped disabled and always runs in safe mode.

Quick start

  1. Add the SLACK_WEBHOOK_URL secret.
  2. Import the flow and set host, port, required plus network for Docker.
  3. Run it once and read the findings.
  4. Run it with auto_remediate: true and dry_run: false to enable persistence, then write the same settings to redis.conf.
  5. Enable the every_15_minutes trigger, which always runs in safe mode.

How to extend

  • Loop over a list of hosts to check every instance in one execution.
  • Add CONFIG REWRITE after verify_result when your instances run with a writable config file.
  • Check replicas too, with INFO replication, and alert when a replica is disconnected.
  • Copy the RDB file to object storage after the verified BGSAVE for an off-host backup.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.