Loop icon
Sequential icon
RedisCLI icon
Docker icon
OutputValues icon
Log icon
If icon
SlackIncomingWebhook icon
Fail icon
Schedule icon

Redis Eviction Policy Guard

Catch Redis caches that reject writes with OOM and stores that silently evict data, alert Slack, set maxmemory-policy with CONFIG SET and verify.

Categories
DataInfrastructure

The right maxmemory-policy depends entirely on what an instance holds, and the wrong one fails in two opposite ways:

  • A cache with noeviction, the default, stops accepting writes once it reaches maxmemory: every SET fails with OOM command not allowed, and the application sees errors instead of a cache miss.
  • A cache with no maxmemory at all grows until the host runs out of memory.
  • A store with an eviction policy quietly deletes data under memory pressure. Typical stores are sessions, job queues, rate-limit counters and locks.

This blueprint reads maxmemory, maxmemory-policy and the eviction and error counters of every instance, and checks them against the role you declare. It alerts Slack, and can apply the right setting with CONFIG SET, then read it back to verify.

This blueprint was created by zkasuran.

Findings

Finding Role Severity Rule Fix
STORE_EVICTS STORE Critical Any policy other than noeviction, with the keys already evicted maxmemory-policy noeviction
CACHE_REJECTS_WRITES CACHE High noeviction, with the error replies so far maxmemory-policy <cache_policy>
CACHE_UNBOUNDED CACHE High maxmemory 0 maxmemory <cache_maxmemory>
CACHE_VOLATILE_POLICY CACHE Medium A volatile-* policy, which only evicts keys with a TTL Report only
UNREACHABLE any High No CONFIG reply Report only
INVALID_ROLE other High Role is not CACHE or STORE Report only

How it works

  1. read (io.kestra.plugin.core.flow.Loop) runs CONFIG GET maxmemory-policy, CONFIG GET maxmemory and INFO stats on each instance with io.kestra.plugin.redis.cli.RedisCLI, read-only. An unreachable instance does not stop the others.
  2. findings applies the rules per role in one jq expression. summary logs the result.
  3. route (io.kestra.plugin.core.flow.If):
    • matching: logs it.
    • findings: alert posts to Slack.
      • remediate_gate runs only when auto_remediate is true and dry_run is false.
      • remediate (concurrencyLimit: 1) runs each CONFIG SET in its own task.
      • reread reads the settings again, and verify_result fails if any instance still does not match its role.
  4. errors alerts Slack when the flow fails.

What you get

  • One view of the eviction settings of all your Redis instances, judged by what each one holds.
  • The cost so far: keys already evicted from stores, write errors already returned by caches.
  • The setting each role needs, applied and verified, with a reminder to persist it.

Who it's for

  • Teams that run Redis both as a cache and as a store for sessions, queues or locks.
  • SREs who have seen OOM command not allowed errors from a full cache, or lost sessions after a traffic spike.
  • Teams evaluating the Redis plugin with a RedisCLI example.

Why orchestrate this with Kestra

The eviction policy is set once, often by a Helm chart default, and never checked against the instance's role. Kestra keeps the role of every instance next to the flow and checks them on a schedule. It sends mismatches to Slack with their impact, applies the fix behind auto_remediate and dry_run, verifies it, and keeps a history of every change.

Tested end to end

On Kestra 2.0.5 OSS against three Redis 7 containers, with a local HTTP sink standing in for Slack:

  • cache bp-rcache: maxmemory 4mb, noeviction. Filling it, 992 of 3,000 SET failed with OOM command not allowed;
  • store bp-rqueue: maxmemory 64mb, allkeys-lru. Filling it, Redis evicted 4,853 session keys;
  • cache bp-rnolimit: no maxmemory.
Run Inputs Result
1 defaults 4 findings, with the 992 error replies and 4,853 evicted keys. Alert sent
2 auto_remediate: true, dry_run: true Same report. The cache is still noeviction
3 auto_remediate: true, dry_run: false 4 CONFIG SET applied and verified. Then in Redis: a SET on the full cache returns OK and evicts old keys. 2,000 more writes to the full store are rejected with OOM and no key is evicted, so the application gets an error instead of losing data
4 defaults Every instance matches its role
5 unknown host UNREACHABLE reported

Prerequisites

  • Redis instances reachable from the Docker containers the RedisCLI tasks start. CONFIG must be allowed for remediation.
  • Decide the role of each instance: CACHE if losing a key is acceptable, STORE if not.
  • Local testing:
    • docker run -d --name redis-cache redis:7-alpine redis-server --maxmemory 4mb --maxmemory-policy noeviction;
    • fill it with SET until writes fail.

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
instances 2 example hosts Host to role, CACHE or STORE
port 6379 Port on every instance
cache_policy allkeys-lru Policy applied to caches
cache_maxmemory 256mb Limit applied to caches with none
network empty Docker network for the redis-cli containers
auto_remediate false Allow CONFIG SET
dry_run true Must be false for a change to apply

Quick start

  1. Add the SLACK_WEBHOOK_URL secret.
  2. Import the flow and list your instances with their role in instances.
  3. Run it once and read the findings.
  4. Run it with auto_remediate: true and dry_run: false, then persist the settings in redis.conf or with CONFIG REWRITE.
  5. Enable the hourly trigger, which always runs in safe mode.

How to extend

  • Read the role from your inventory instead of a static map.
  • Alert when evicted_keys grows between two runs on a cache, a sign it is undersized.
  • Add password support with password: "{{ secret('REDIS_PASSWORD') }}" on each RedisCLI task.
  • Run CONFIG REWRITE after verify_result when your instances use a writable config file.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.