Redis Get Cache icon

Redis Get Cache

Recupera dados do Redis com verificação de expiração e renovação inteligente

Overview

This node retrieves cached data from a Redis database with intelligent expiration checking and renewal signaling. It is designed to fetch a value by its key, verify if the cache entry exists, check its time-to-live (TTL), and determine whether the cache is still valid, invalid, or needs renewal based on a configurable threshold.

Common scenarios include:

  • Efficiently retrieving user session data or profiles stored in Redis.
  • Implementing cache validation logic that triggers cache refresh before expiration.
  • Managing distributed cache states where timely renewal of cached data is critical.

For example, you might use this node to get a user's profile data cached in Redis under the key user:123:profile. If the TTL is below a certain threshold (e.g., 5 minutes), the node flags the cache as needing renewal so that subsequent workflow steps can refresh the cache proactively.

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 renewal. Recommended: 10-20% of total TTL. For example, 300 means 5 minutes before expiration.

Output

The node has three output branches:

  1. Valid Cache
    Items where the cache exists and the TTL is above the renewal threshold. Each item’s JSON contains:

    • key: The Redis key queried.
    • value: The cached data (parsed JSON object if possible, otherwise raw string).
    • ttl: Time to live in seconds, or "never" if no expiration is set.
    • exists: true indicating the key exists.
    • timestamp: ISO timestamp of retrieval.
    • status: "valid_cache".
  2. Invalid Cache
    Items where the key does not exist or has expired. Each item’s JSON contains:

    • key: The Redis key queried.
    • exists: false.
    • ttl: -1.
    • timestamp: ISO timestamp of retrieval.
    • status: "invalid_cache".
  3. Needs Renewal
    Items where the cache exists but the TTL is less than or equal to the renewal threshold (and greater than zero). Each item’s JSON contains the same fields as valid cache items but with:

    • status: "needs_renewal".

No binary data output is produced by this node.

Dependencies

  • Requires a Redis server connection configured via credentials including host, port, optional username, password, database number, and TLS settings.
  • Uses an internal Redis connection helper class to manage connections.
  • The node expects the Redis server to support the GET and TTL commands.

Troubleshooting

  • Common issues:

    • Connection failures due to incorrect Redis credentials or network issues.
    • Keys not found because they were never set or have expired.
    • Parsing errors if cached data is not valid JSON (the node falls back to returning raw strings).
  • Error messages:

    • "Erro ao recuperar do Redis: <message>" indicates a failure during Redis operations; verify credentials and Redis server availability.
    • "Ocorreu um erro desconhecido" is a generic catch-all error; check logs for more details.
  • Resolution tips:

    • Ensure the Redis credentials are correct and the server is reachable.
    • Confirm the keys used match those set previously.
    • Adjust the renewal threshold according to your cache expiration strategy.

Links and References

Discussion