Memory State icon

Memory State

Store and retrieve key-value pairs in memory state

Overview

This node provides a simple in-memory key-value store within an n8n workflow. It allows users to store, retrieve, delete, and list JSON objects by keys during workflow execution. This is useful for maintaining transient state or sharing data between different parts of a workflow without external storage.

Common scenarios include:

  • Caching API responses temporarily to avoid repeated calls.
  • Storing user session data or intermediate results.
  • Managing feature flags or configuration values dynamically within a workflow.
  • Retrieving default values if no stored value exists for a key.

For example, you can set a user profile object under a key, then later retrieve it or list all keys matching a pattern like user:*.

Properties

Name Meaning
Action The operation to perform. Options: Delete, Get, Get with Default, Keys, Set
Key The key string used to store, retrieve, or delete a value (e.g., "session:123")
Value The JSON object to store for the given key (required when Action is "Set"). Must be a JSON object, not array or primitive.
Default Value The JSON object to return and store if the key is not found (used only with "Get with Default" action). Must be a JSON object.
Get Values Boolean flag indicating whether to retrieve values along with keys when listing keys (only for "Keys" action)
Filter Pattern (RegEx) Optional regular expression to filter keys when listing them. Leave empty to list all keys (only for "Keys" action)

Output

The output is an array of items where each item contains a json field with the following structure depending on the action:

  • Set: { key: string, value: object } — the stored key and its JSON object value.
  • Get: { key: string, value: object|null } — the requested key and its stored value or null if not found.
  • Get with Default: { key: string, value: object } — the key and either the stored value or the provided default value if none was found.
  • Delete: { key: string, success: true } — confirmation that the key was deleted.
  • Keys:
    • If Get Values is false: { key: string } — list of keys matching the optional filter.
    • If Get Values is true: { key: string, value: object|null } — keys with their corresponding values.

No binary data is output by this node.

Dependencies

  • Requires an internal memory store service accessible via memoryStore with async methods: get(key), set(key, value), delete(key), and keys(filterPattern).
  • No external API keys or credentials are needed.
  • No special environment variables or n8n configurations required beyond standard node setup.

Troubleshooting

  • Key is required and cannot be empty: Ensure the "Key" property is set and not just whitespace.
  • Value must be a JSON object: When setting a value, it must be a valid JSON object (not an array, primitive, or null). Check your JSON syntax carefully.
  • Default value must be a JSON object: For "Get with Default" action, the default value must also be a valid JSON object.
  • Error listing keys: If using a regex filter pattern, ensure it is a valid regular expression.
  • Unsupported action: Only the listed actions are supported; verify the "Action" property.
  • General errors will be wrapped with context about which item index caused the failure.

Links and References

Discussion