Redis Manipulate Cache icon

Redis Manipulate Cache

Manipula dados existentes no Redis de forma parcial

Overview

The node "Redis Manipulate Cache" allows partial manipulation of existing data stored in a Redis database. It is designed to update or modify specific fields within Redis keys without overwriting the entire value, which is especially useful when working with complex JSON objects or Redis hashes.

Common scenarios where this node is beneficial include:

  • Updating a single field inside a JSON object stored as a string in Redis.
  • Modifying a specific field in a Redis hash.
  • Appending or removing items from arrays nested inside JSON objects stored in Redis.
  • Preserving the original time-to-live (TTL) of the Redis key while making updates.

Practical example:

  • You have user profile data stored as a JSON string under the key user:123:profile. You want to update just the user's name without replacing the whole profile object.
  • You store session attributes in a Redis hash and need to update one attribute efficiently.
  • You maintain a list of notifications inside a JSON array in Redis and want to append a new notification.

Properties

Name Meaning
Key The Redis key containing the data to be manipulated (e.g., user:123:profile).
Field Name The name of the field in the Redis hash to update (used only for the "Update Hash Field" operation).
New Value The new value to set for the specified field. Accepts valid JSON if needed.
Preserve TTL Boolean flag indicating whether to keep the original expiration time of the Redis key after modification.

Output

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

  • key: The Redis key that was manipulated.
  • operation: The operation performed (e.g., "updateHashField").
  • success: A boolean indicating if the operation succeeded.
  • result: The updated data after the operation:
    • For hash updates, this is the full hash object after modification.
    • For JSON manipulations, this is the updated JSON object.
  • preservedTtl: The remaining TTL (in seconds) preserved if the "Preserve TTL" option was enabled; otherwise, null.
  • timestamp: ISO timestamp of when the operation was performed.

The node does not output binary data.

Dependencies

  • Requires a Redis server connection configured via credentials including host, port, optional username, password, database index, and TLS settings.
  • Uses a Redis client instance initialized internally.
  • Requires the Redis key to exist before performing operations.
  • The node expects valid JSON strings when manipulating JSON fields or arrays.

Troubleshooting

Common Issues

  • Key does not exist: If the specified Redis key does not exist, the node throws an error indicating the missing key.
  • Invalid JSON: When updating JSON fields or arrays, if the stored data or the new value is not valid JSON, the node will throw a JSON parsing error.
  • Field path not found: For JSON operations, if the specified field path does not exist in the JSON object, the node may create intermediate objects but will error if trying to remove from a non-array field.
  • Field is not an array: When removing from a JSON array, if the target field is not an array, an error is thrown.
  • TTL preservation issues: If the TTL is preserved but the key has no expiration or TTL is negative, the expiration is not reset.

Error Messages and Resolutions

  • A chave "<key>" não existe no Redis
    Resolution: Verify the Redis key exists before running the node.

  • Dados não encontrados
    Resolution: The key exists but contains no data; ensure the key holds the expected data type.

  • Falha ao manipular JSON: <message>
    Resolution: Check that the stored data and new values are valid JSON strings.

  • Caminho "<fieldPath>" não encontrado
    Resolution: Confirm the field path is correct and exists in the JSON structure.

  • O campo "<fieldName>" não é um array
    Resolution: Ensure the target field is an array before attempting removal.

  • Erro ao manipular dados no Redis: <message>
    Resolution: General error; check Redis connectivity, credentials, and data validity.

Links and References

Discussion