Redis Manipulate Cache icon

Redis Manipulate Cache

Manipula dados existentes no Redis de forma parcial

Overview

This node allows partial manipulation of existing data stored in a Redis cache. It is designed to update or modify specific fields within JSON objects or hashes stored under Redis keys, without needing to overwrite the entire data structure. This is particularly useful when working with large JSON documents or hash maps where only a small part needs to be changed.

Common scenarios include:

  • Updating user profile information stored as JSON in Redis.
  • Modifying specific fields in Redis hashes used for session or configuration data.
  • Appending or removing items from arrays nested inside JSON objects stored in Redis.

For example, you can update a user's name inside a JSON object stored at key user:123:profile, append a new item to an array field like items[0].title, or remove the last element from a JSON array.

Properties

Name Meaning
Key The Redis key containing the data to manipulate (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 or plain values. Used in update and append operations.
Preserve TTL Boolean flag indicating whether to keep the original expiration time (TTL) of the Redis key after modification. Defaults to true.

Note: For the "Update Hash Field" operation, instead of Field Path, the property Field Name is used to specify the hash field to update.

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 the operation. For JSON operations, this is the updated JSON object; for hash updates, it is the full hash after modification.
  • 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 connection configured via credentials providing host, port, database number, username, password, and optional TLS settings.
  • The node uses a Redis client library internally to connect and perform commands.
  • Proper Redis credentials must be set up in n8n before using this node.

Troubleshooting

  • Key does not exist: If the specified Redis key does not exist, the node throws an error stating the key was not found. Ensure the key exists before running the node.
  • 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. Verify the data format and provide valid JSON strings where required.
  • Field path not found: For removal operations, if the specified field path does not exist or is not an array, the node will throw an error. Double-check the field path and data structure.
  • Preserving TTL issues: If the TTL is preserved but the key has no expiration, the TTL value will be -1 or 0, which means no expiration is set. This is expected behavior.
  • Permission or connection errors: Ensure Redis credentials are correct and the Redis server is reachable.

Links and References

Discussion