Schedule icon
Ttl icon
If icon
Switch icon
RedisCLI icon
Log icon
SlackIncomingWebhook icon

Redis Key TTL Expiry Risk Sentinel

Check a Redis key's TTL, alert on no-expiry or near-expiry risk, and optionally remediate with EXPIRE.

Categories
DataInfrastructure

A Redis key with no TTL at all persists forever - exactly the leak that fills an instance's memory one forgotten session token at a time. A key with a TTL that is about to run out is a different but related risk: whatever depends on it is about to lose it. This blueprint reads one key's TTL, alerts on either risk (or on the key being missing entirely), and can re-apply a safe TTL with EXPIRE - never touching the key's actual value - behind two independent, explicit gates.

How it works

  1. periodic_ttl_check (io.kestra.plugin.core.trigger.Schedule) runs every 15 minutes, always forcing auto_remediate: "false" and dry_run: "true" through its own inputs: override regardless of this flow's defaults. Shipped disabled so you can validate a manual run first.
  2. check_key_ttl (io.kestra.plugin.redis.string.Ttl) runs TTL on redis_key, returning -1 (no expiry), -2 (missing), or the remaining seconds.
  3. evaluate_ttl_risk (io.kestra.plugin.core.flow.If) flags risk whenever ttl < min_ttl_seconds - a single comparison that also catches both sentinel values, since -1 and -2 are always less than any positive threshold.
    • then (at risk): check_key_exists (io.kestra.plugin.core.flow.If on ttl != -2) separates a remediable key (exists, unsafe TTL) from a missing one. For a remediable key, route_remediation (io.kestra.plugin.core.flow.Switch on auto_remediate) either considers remediation ("true", gated again by dry_run through check_dry_run) or only logs that remediation is disabled ("false"). A missing key logs that EXPIRE cannot help. alert_ttl_risk always fires to Slack regardless of which of those ran.
    • else (healthy): log_ttl_healthy records a clean check.
  4. log_audit_complete always runs last, printing the headline numbers regardless of which branch fired.
  5. The errors block alerts Slack separately if the flow itself fails - an unreachable Redis instance must not read as "no risk".

What you get

  • A specific, actionable distinction between "no TTL set", "about to expire", and "missing entirely" - not one generic alert.
  • Remediation (EXPIRE) that only ever changes the key's TTL, never its value - no risk of clobbering session or cache data.
  • Two independent gates (auto_remediate, dry_run) between "risk detected" and "TTL actually changed".
  • A final status log every run, risk or not, so the execution history doubles as a TTL history for that key.

Who it's for

  • Platform teams running Redis as a session store or token registry who need to catch a missing-TTL leak before memory pressure forces an eviction storm.
  • SREs who want a specific key (a feature flag, a leader-election lock, a rate-limit counter) watched for unsafe expiry behavior.
  • Anyone evaluating the Redis plugin who wants a worked example of Ttl paired with RedisCLI for an operation the structured tasks cannot do alone.

Why orchestrate this with Kestra

TTL and EXPIRE are one-shot Redis commands with no memory of the last check, no threshold logic, and no notification path. Kestra supplies the schedule, the risk classification as a first-class branch, two independent authorization gates before anything is changed, and an execution history that shows exactly when a key went unsafe and whether it was fixed.

Prerequisites

  • Docker available to the Kestra Worker (io.kestra.plugin.redis.cli.RedisCLI defaults to the Docker task runner with the redis:7-alpine image; io.kestra.plugin.redis.string.Ttl connects directly over the Redis protocol, no container needed on the Worker itself for that task).
  • Network access from the Kestra Worker to redis_host:redis_port.
  • A Slack incoming webhook for alerts.

Local testing: docker run -d --name redis-sentinel -p 6380:6379 redis:7-alpine docker network connect YOUR_KESTRA_NETWORK redis-sentinel (only needed if the Kestra Worker runs in a separate Docker network than this container; if you map the host port, set redis_port to 6380 or whatever host port you chose, since 6379 is avoided here only as a documentation convention, not a hard requirement).

Secrets

  • SLACK_WEBHOOK_URL: Slack incoming webhook used by alert_ttl_risk and the errors block.
  • This blueprint's check_key_ttl.url and remediate_key_ttl's host/port assume an unauthenticated local instance, matching the plugin's own documentation examples. For a password-protected instance, set url: "redis://:{{ secret('REDIS_PASSWORD') }}@{{ inputs.redis_host }}:{{ inputs.redis_port }}/0" on check_key_ttl, and add password: "{{ secret('REDIS_PASSWORD') }}" to remediate_key_ttl - never place the password in redis_host/redis_port or any other input.
  • In Kestra OSS (no Enterprise secrets backend), secrets are supplied as environment variables prefixed SECRET_, base64-encoded, and read back in flows with {{ secret('NAME') }} - for example SECRET_SLACK_WEBHOOK_URL=$(echo -n 'https://hooks.slack.com/...' | base64). This keeps credentials out of the flow YAML but, per Kestra's own documentation, offers no encryption at rest or access control beyond the host environment; use the Enterprise secrets backend for stronger guarantees.

Inputs

  • redis_host (STRING, default localhost): Redis server hostname.
  • redis_port (INT, default 6379): Redis server port.
  • redis_key (STRING, default session:example): the single key audited.
  • min_ttl_seconds (INT, default 300): a TTL below this, or -1/-2, counts as at risk.
  • remediation_ttl_seconds (INT, default 3600): TTL applied by EXPIRE when remediation runs.
  • auto_remediate (SELECT: "false", "true"; default "false"): must be "true" for remediation to even be considered.
  • dry_run (SELECT: "true", "false"; default "true"): must be explicitly "false", together with auto_remediate: "true", for EXPIRE to actually run.

Outputs

  • outputs.check_key_ttl.ttl / .key: the raw TTL result for every run.
  • outputs.remediate_key_ttl.vars.command_1: redis-cli's own reply to the EXPIRE command, present only when remediation actually ran.

Quick start

  1. Start Redis locally with the command above (or point at an existing instance) and set a key with no TTL: redis-cli -p 6380 SET session:example "test".
  2. Add the SLACK_WEBHOOK_URL secret.
  3. Run the flow manually with the defaults and confirm alert_ttl_risk fires (a key with no TTL has ttl: -1, always below min_ttl_seconds) and, with auto_remediate: "false", log_remediation_disabled logs without changing anything.
  4. Run once with auto_remediate: "true" and dry_run: "true" and confirm log_dry_run_remediation describes the EXPIRE without running it.
  5. Run once with auto_remediate: "true" and dry_run: "false" and confirm remediate_key_ttl runs, then verify with redis-cli -p 6380 TTL session:example that the TTL is now set.
  6. Enable periodic_ttl_check once you trust the check; it always runs in the safe auto_remediate: "false" / dry_run: "true" mode regardless of what you leave the flow's own defaults set to.

How to extend

  • Loop over several keys with io.kestra.plugin.core.flow.Loop, declaring the loop's own outputs: property so each iteration's Ttl result is available after the loop closes - the current single-key design intentionally avoids that added complexity.
  • Use io.kestra.plugin.redis.cli.RedisCLI with a KEYS or SCAN command to discover candidate keys by pattern instead of auditing one known key.
  • Route the missing-key branch (log_key_missing) to a different Slack channel or severity than the unsafe-TTL branch, since a missing key often means something upstream never ran at all.
  • Add io.kestra.plugin.redis.string.Get before remediation to log the key's current value alongside its TTL for a fuller audit trail (read-only, never fed into EXPIRE).

Pitfalls

  • -1 and -2 are TTL values, not error codes. Redis's own TTL command overloads a single integer field with these sentinels; a null/missing-field check would miss both. This blueprint relies on ttl < min_ttl_seconds catching all three cases (unsafe-but-positive, no-expiry, missing) in one comparison.
  • There is no structured Expire task in this plugin. Verified from source: only Ttl, Get, Set, Delete, Increment exist under redis.string. Setting a TTL without rewriting the value requires io.kestra.plugin.redis.cli.RedisCLI running a raw EXPIRE command - using Set instead would silently overwrite the key's actual content.
  • EXPIRE on a missing key is a silent no-op, not a remediation. The check_key_exists gate exists specifically so a missing key is reported as missing, never papered over by an EXPIRE call that would appear to succeed while doing nothing.
  • auto_remediate and dry_run are independent gates, not a single boolean. Both must be "true"/"false" respectively for EXPIRE to run; setting only one leaves the other still blocking.
  • Switch case keys "true"/"false" are quoted strings. auto_remediate renders as the literal string "true" or "false"; unquoted true:/false: YAML map keys would parse as booleans instead and would not match.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.