Redis Manipulate Cache icon

Redis Manipulate Cache

Manipula dados existentes no Redis de forma parcial

Overview

This node, named "Redis Manipulate Cache," allows partial manipulation of existing data stored in a Redis database. It is designed to update or modify specific fields within JSON objects or hashes stored under Redis keys without replacing the entire data entry. This capability is useful when working with complex cached data structures where only certain parts need updating, such as user profiles, session data, or configuration objects.

Common scenarios include:

  • Updating a nested field inside a JSON object stored in Redis (e.g., changing a user's name).
  • Modifying a specific field in a Redis hash.
  • Appending new items to an array inside a JSON object stored in Redis.
  • Removing the last item from an array inside a JSON object stored in Redis.

Practical example: Suppose you cache user profiles as JSON objects in Redis under keys like user:123:profile. You can use this node to update just the user's email address or append a new role to their roles array without overwriting the entire profile.

Properties

Name Meaning
Key The Redis key containing the data to be manipulated (e.g., user:123:profile).
Field Path The path to the field to update inside the JSON object, using dot notation for nested fields (e.g., user.name or items[0].title). Required for JSON operations.
New Value The new value to set for the specified field. Accepts valid JSON strings if needed.
Preserve TTL Boolean flag indicating whether to keep the original expiration time (TTL) of the Redis key after modification. Defaults to true.

Additional properties depending on operation:

Name Meaning
Operation The type of manipulation to perform. Options are:
- Update JSON Field: Update a specific field in a JSON object.
- Update Hash Field: Update a specific field in a Redis hash.
- Append to JSON Array: Add an item to an array inside a JSON object.
- Remove from JSON Array: Remove the last item from an array inside a JSON object.
Field Name The name of the field in the Redis hash to update. Required for "Update Hash Field" operation.

Output

The node outputs an array of JSON objects, each corresponding to one input item processed. Each output object contains:

  • key: The Redis key that was manipulated.
  • operation: The operation performed (e.g., updateJsonField).
  • success: Boolean indicating if the operation succeeded.
  • result: The updated data after manipulation:
    • For JSON operations, this is the updated JSON object.
    • For hash operations, this is the full hash object after update.
  • preservedTtl: The TTL (time to live) preserved on the key if the "Preserve TTL" option was enabled; otherwise null.
  • timestamp: ISO string timestamp of when the operation was performed.

The node does not output binary data.

Dependencies

  • Requires a Redis server accessible with credentials configured in n8n.
  • Needs an API key or authentication token for Redis connection (configured via n8n credentials).
  • Uses a Redis client library internally to connect and manipulate data.

Troubleshooting

Common Issues

  • Key does not exist: If the specified Redis key does not exist, the node throws an error indicating the key was not found.
  • Invalid JSON data: When manipulating JSON fields, if the stored data is not valid JSON or the new value is invalid JSON, errors will occur.
  • Field path not found: For removal operations, if the specified field path does not exist or is not an array, an error is thrown.
  • TTL preservation issues: If preserving TTL but the key has no TTL or it expires during operation, the TTL may not be restored correctly.

Error Messages and Resolutions

  • "A chave \"<key>\" não existe no Redis": The Redis key does not exist. Verify the key name and ensure the data is present.
  • "Dados não encontrados": No data found at the key. Check if the key holds any data.
  • "Falha ao manipular JSON: <message>": JSON parsing or manipulation failed. Ensure the stored data and new values are valid JSON.
  • "Falha ao manipular array JSON: <message>": Error manipulating JSON arrays. Confirm the field path points to an array and the new value is appropriate.
  • "O campo \"<field>\" não é um array": The targeted field is not an array. Adjust the field path or data structure accordingly.
  • "Caminho \"<path>\" não encontrado": The specified field path does not exist in the JSON object. Verify the path syntax.

To resolve these errors, verify the Redis data structure, ensure correct JSON formatting, and confirm the field paths used.

Links and References

Discussion