Overview
This node retrieves cached data from a Redis database with intelligent expiration checking and renewal signaling. It is useful in workflows where you want to fetch previously stored data from Redis and handle cache validity proactively. The node checks if the cache key exists, determines its time-to-live (TTL), and categorizes the cache status into three outputs: valid cache, invalid cache (missing or expired), and cache that needs renewal soon based on a configurable threshold.
Practical examples include:
- Fetching user session data stored in Redis and triggering renewal before expiration.
- Retrieving API response caches and deciding whether to use them or refresh.
- Managing temporary tokens or configuration values with automatic renewal alerts.
Properties
Name | Meaning |
---|---|
Key | The Redis key to retrieve data from. Must match the key used when setting the cache. |
Renewal Threshold (seconds) | Time in seconds before the cache expiration to trigger a renewal signal. Recommended 10-20% of TTL. Example: 300 means 5 minutes before expiration. |
Output
The node has three separate outputs:
Valid Cache
Emits items where the cache key exists and is not close to expiration. Each item contains a JSON object with:key
: The Redis key queried.value
: The parsed cached value (JSON parsed if possible, otherwise raw string).ttl
: Time to live in seconds, or"never"
if no expiration is set.exists
: Alwaystrue
.timestamp
: ISO timestamp of retrieval.status
:"valid_cache"
.
Invalid Cache
Emits items where the cache key does not exist or has expired. Each item contains:key
: The Redis key queried.exists
:false
.ttl
:-1
.timestamp
: ISO timestamp of retrieval.status
:"invalid_cache"
.
Needs Renewal
Emits items where the cache key exists but its TTL is less than or equal to the configured renewal threshold (and greater than zero). Items have the same structure as valid cache but with:status
:"needs_renewal"
.
No binary data output is produced by this node.
Dependencies
- Requires a Redis server connection with credentials including host, port, optional username, password, and TLS settings.
- The node depends on an external Redis connection utility bundled as
RedisConnection
for managing connections and commands. - Proper Redis credentials must be configured in n8n for authentication.
Troubleshooting
Common issues:
- Connection failures due to incorrect Redis host, port, or authentication details.
- Missing keys returning invalid cache output.
- Parsing errors if cached data is not valid JSON (the node falls back to raw string).
Error messages:
"Erro ao recuperar do Redis: <message>"
indicates a Redis operation failure; verify connectivity and credentials."Ocorreu um erro desconhecido"
indicates an unexpected error; check node logs and Redis server status.
Resolution tips:
- Ensure Redis credentials are correct and the server is reachable.
- Confirm the cache key exists and matches the one used during caching.
- Adjust the renewal threshold according to your cache expiration strategy.