Overview
The Redis Message Aggregator node collects and aggregates messages associated with a specific key (such as a user ID, group ID, or a combination) using Redis as a backend. It is designed to handle multiple triggers that send messages independently but need to be combined into a single aggregated output intelligently.
This node supports two main strategies for aggregation:
- Smart Wait: Waits until no new messages arrive within a specified timeout period before outputting the aggregated message.
- Immediate on Complete: Outputs the aggregated message immediately once it detects that the last message ends with one of the predefined "end words" indicating completion.
Practical Use Cases
- Combining chat messages from a user or group that arrive in parts into a single coherent message.
- Collecting sensor or event data over a short time window before processing.
- Aggregating fragmented notifications or logs before sending them downstream.
For example, if a chatbot receives multiple partial inputs from a user, this node can wait until the user finishes typing (detected by a pause or an end word) and then output the full combined message.
Properties
| Name | Meaning |
|---|---|
| Key | The identifier used to group messages (e.g., user ID, group ID, or a combination like user123_group456). |
| Message Content | The content of the message to be aggregated. |
| Wait Time (Seconds) | The delay time in seconds after the last message before outputting the aggregated result (used in Smart Wait). |
| Strategy | The aggregation strategy to use: - Smart Wait: Waits intelligently until no new messages arrive. - Immediate on Complete: Outputs immediately when a complete sentence is detected. |
| End Words | (Only shown if Strategy is "Immediate on Complete") A comma-separated list of words that indicate the end of a message. When the last message ends with any of these words, aggregation outputs immediately. |
Output
The node outputs JSON objects describing the aggregation status and results. The structure varies depending on the strategy and state:
- status: Indicates the current state, e.g.,
"messages_aggregated","message_stored","timeout","no_messages". - key: The aggregation key used.
- aggregatedMessage: The combined message string (present when messages are aggregated).
- messageCount: Number of messages aggregated.
- originalMessages: Array of original message objects with
contentandtimestamp. - trigger: What caused the output, e.g.,
"immediate_complete","smart_timeout". - aggregatedAt: ISO timestamp when aggregation occurred.
- reason: Explanation for certain statuses like waiting or timeout.
- totalWaitTime: Total wait time in seconds (for smart wait).
If binary data were involved, it would be summarized here, but this node only handles textual JSON data.
Dependencies
- Requires a Redis server accessible via credentials configured in n8n.
- Needs an API key credential or connection details for Redis (host, port, password, TLS, etc.).
- Uses the
ioredislibrary internally to interact with Redis. - No other external services are required.
Troubleshooting
Common Issues
- Missing Redis Credentials: The node will throw an error if Redis credentials are not provided or invalid.
- Connection Failures: Network issues or incorrect Redis connection parameters can cause connection errors.
- Timeouts: If messages expire in Redis before aggregation completes, the node may output a
"no_messages"or"timeout"status. - Lock Contention: The node uses Redis locks to prevent concurrent aggregations; if locking fails repeatedly, aggregation might be delayed or skipped.
Error Messages
"Không tìm thấy Redis credentials": Means Redis credentials are missing; ensure proper credentials are set up.- Errors containing
"READONLY"indicate Redis is in read-only mode; check Redis server status. - Other errors include JSON parsing failures or Redis command errors; verify message content format and Redis health.
Resolution Tips
- Verify Redis credentials and connectivity.
- Adjust wait times according to message frequency.
- Ensure end words are correctly specified for immediate strategy.
- Monitor Redis server logs for operational issues.