# Redis - Command

> Execute commands on a Redis key-value store.

Source: https://docs.sommatic.ai/en/nodes/integrations.redis.command/

- Slug: `integrations.redis.command`
- Family: Integrations
- Version: 1.0.0
- Status: Available
- Execution: async

Execute commands on a Redis key-value store.

Connect your Redis instance and automate cache and data operations. Send any Redis command with arguments — from simple key-value reads to complex data structure manipulation.

**Operations:**
- **GET / SET / MGET / MSET:** Read and write string values, bulk operations.
- **HGET / HSET / HGETALL:** Work with hash maps (field-value pairs).
- **LPUSH / RPUSH / LPOP / LRANGE:** Manage ordered lists.
- **SADD / SMEMBERS / SINTER:** Work with sets and intersections.
- **ZADD / ZRANGE / ZRANGEBYSCORE:** Sorted sets with scoring.
- **DEL / EXISTS / TTL / EXPIRE:** Key lifecycle and expiration management.
- **INCR / DECR:** Atomic counters.
- **PUBLISH:** Publish messages to channels.

## Configuration

- `connection_id` (string, required): Credential for your Redis instance. Accepts credentials of type `connection-string` (redis:// URI) or `basic-auth` (password + host + port).
- `command` (string, required, accepts expressions): Redis command to execute (e.g., GET, SET, HGET, LPUSH, DEL).
- `args` (array, optional): Command arguments (e.g., key, value, field name).

## Output ports

- `out` (default): Command result
- `error`: Command execution error

## Input contract

- `connection_id` (string, required)
- `command` (string, required)
- `args` (array, optional)

## Output contract

- `result` (object, optional): Redis command response

## In expressions

What a later node can read from this node's output with `$("Redis - Command").item.json.<path>` (write your node's label instead of `Redis - Command`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Redis - Command").item.json.result` (object) = `"{\"status\":\"open\",\"total\":129.99}"`: Redis command response


## How it works

Sends one raw Redis command (GET, SET, HGET, LPUSH, DEL…) with its arguments and returns the Redis reply under `result`.

1. Resolves the expressions of the node config. Empty `connection_id` and `command` fall back to the incoming item; `args` falls back when it is missing or an empty array.
2. Resolves the connection: a `redis://` URL in `connection_id`, a `connection-string` credential (any URL the client accepts, including `rediss://`), or a `basic-auth` / `object` credential with `host`, `port` (default 6379) and optional `password`.
3. Upper-cases `command`, drops `null` / `undefined` arguments, converts the rest with `String()` and sends the command as is.
4. Disconnects and returns `{ result }` on `out` with the reply: a string, a number, `null` or an array, depending on the command.

## In a workflow

### Node

```json
{
  "node_id": "node-cache-order",
  "label": "Read cached order",
  "operator_slug": "integrations.redis.command",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "command": "GET",
    "args": [
      "order:{{ $json.order_id }}"
    ]
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "result": "{\"status\":\"open\",\"total\":129.99}"
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

Redis replied. A GET on a missing key also leaves here, with `result: null`.

```json
{
  "result": "{\"status\":\"open\",\"total\":129.99}"
}
```

### `error`

Validation, credential resolution, the connection or the command failed.

```json
{
  "error": "WRONGTYPE Operation against a key holding the wrong kind of value"
}
```

## Behaviour in the code

- `args`: Every argument is converted with `String()`: an object becomes `[object Object]`. Serialize JSON values to a string before passing them.
- `connection_id`: A structured credential builds a plain `redis://` URL without TLS and without a username. For TLS or ACL users, store the full URL as a `connection-string` credential.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `connection_id is required` | `error` | No credential in the config or in the incoming item. |
| `command is required` | `error` | `command` is empty. |
| `Credential <connection_id> (type '<type>') missing host` | `error` | A structured credential lacks `host`. |
| `ERR <Redis error message>` | `error` | Redis rejected the command (unknown command, wrong number of arguments…); the message is passed through. |

## Notes and limits

- A new connection is opened and closed on every run; the node does not retry. Non-idempotent commands such as INCR or LPUSH run exactly once per execution.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "integrations.redis.command",
  "name": "Redis - Command",
  "category": "integrations",
  "version": "1.0.0",
  "description": "Execute commands on a Redis key-value store.\n\n  Connect your Redis instance and automate cache and data operations. Send any Redis command with arguments — from simple key-value reads to complex data structure manipulation.\n\n  **Operations:**\n  - **GET / SET / MGET / MSET:** Read and write string values, bulk operations.\n  - **HGET / HSET / HGETALL:** Work with hash maps (field-value pairs).\n  - **LPUSH / RPUSH / LPOP / LRANGE:** Manage ordered lists.\n  - **SADD / SMEMBERS / SINTER:** Work with sets and intersections.\n  - **ZADD / ZRANGE / ZRANGEBYSCORE:** Sorted sets with scoring.\n  - **DEL / EXISTS / TTL / EXPIRE:** Key lifecycle and expiration management.\n  - **INCR / DECR:** Atomic counters.\n  - **PUBLISH:** Publish messages to channels.",
  "capabilities": [
    "kv",
    "cache",
    "redis",
    "database"
  ],
  "group": [
    {
      "key": "redis",
      "name": "Redis",
      "icon_url": "/icons/integrations/redis/redis.svg"
    }
  ],
  "icon_url": "/icons/integrations/redis/redis.svg",
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Redis Credential",
        "description": "Credential for your Redis instance. Accepts credentials of type `connection-string` (redis:// URI) or `basic-auth` (password + host + port).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "connection-string",
            "basic-auth"
          ],
          "types": [
            "redis"
          ]
        }
      },
      "command": {
        "type": "string",
        "title": "Command",
        "description": "Redis command to execute (e.g., GET, SET, HGET, LPUSH, DEL).",
        "format": "expression"
      },
      "args": {
        "type": "array",
        "title": "Arguments",
        "description": "Command arguments (e.g., key, value, field name)."
      }
    },
    "required": [
      "connection_id",
      "command"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string"
      },
      "command": {
        "type": "string"
      },
      "args": {
        "type": "array"
      }
    },
    "required": [
      "connection_id",
      "command"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "result": {
        "type": "object",
        "description": "Redis command response"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Result",
      "description": "Command result",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Command execution error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "standard-io",
    "fast-io"
  ],
  "tags": [
    "cache",
    "kv"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://sommatic.ai",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "Redis Credential",
      "description": "Credential for your Redis instance. Accepts credentials of type `connection-string` (redis:// URI) or `basic-auth` (password + host + port).",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "connection-string",
          "basic-auth"
        ],
        "types": [
          "redis"
        ]
      }
    },
    "command": {
      "type": "string",
      "title": "Command",
      "description": "Redis command to execute (e.g., GET, SET, HGET, LPUSH, DEL).",
      "format": "expression"
    },
    "args": {
      "type": "array",
      "title": "Arguments",
      "description": "Command arguments (e.g., key, value, field name)."
    }
  },
  "required": [
    "connection_id",
    "command"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string"
    },
    "command": {
      "type": "string"
    },
    "args": {
      "type": "array"
    }
  },
  "required": [
    "connection_id",
    "command"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "result": {
      "type": "object",
      "description": "Redis command response"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Result",
    "description": "Command result",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Command execution error",
    "is_default": false,
    "supports_condition": false
  }
]
```
