# Upstash (/integrations/upstash)





{/* MANUAL-CONTENT-START:intro */}

Use [Upstash](https://upstash.com/) Redis through its REST API to manage keys, hashes, lists, counters, and expiry. The Command action accepts a Redis command for operations beyond the dedicated actions.

{/* MANUAL-CONTENT-END */}

## Use the block [#usage-instructions]

Connect to Upstash Redis to perform key-value, hash, list, and utility operations via the REST API.

## Actions [#actions]

### Upstash Redis Get [#upstash-redis-get]

Get the value of a key from Upstash Redis.

<ReferenceDetails>
  #### Input [#input]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to retrieve |

  #### Output [#output]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that was retrieved |
  | `value` | json | The value of the key (string), or null if not found |
</ReferenceDetails>

### Upstash Redis Set [#upstash-redis-set]

Set the value of a key in Upstash Redis with an optional expiration time in seconds.

<ReferenceDetails>
  #### Input [#input-1]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to set |
  | `value` | string | Yes | The value to store |
  | `ex` | number | No | Expiration time in seconds (optional) |

  #### Output [#output-1]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that was set |
  | `result` | string | The result of the SET operation (typically "OK") |
</ReferenceDetails>

### Upstash Redis Delete [#upstash-redis-delete]

Delete a key from Upstash Redis.

<ReferenceDetails>
  #### Input [#input-2]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to delete |

  #### Output [#output-2]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that was deleted |
  | `deletedCount` | number | Number of keys deleted (0 if key did not exist, 1 if deleted) |
</ReferenceDetails>

### Upstash Redis Keys [#upstash-redis-keys]

List keys matching a pattern in Upstash Redis. Defaults to listing all keys (\*).

<ReferenceDetails>
  #### Input [#input-3]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `pattern` | string | No | Pattern to match keys (e.g., "user:&#x2A;"). Defaults to "*" for all keys. |

  #### Output [#output-3]

  | Parameter | Type | Description |
  | - | - | - |
  | `pattern` | string | The pattern used to match keys |
  | `keys` | array | List of keys matching the pattern |
  | `count` | number | Number of keys found |
</ReferenceDetails>

### Upstash Redis Command [#upstash-redis-command]

Execute an arbitrary Redis command against Upstash Redis. Pass the full command as a JSON array (e.g., \["HSET", "myhash", "field1", "value1"]).

<ReferenceDetails>
  #### Input [#input-4]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `command` | string | Yes | Redis command as a JSON array (e.g., \["HSET", "myhash", "field1", "value1"]) or a simple command string (e.g., "PING") |

  #### Output [#output-4]

  | Parameter | Type | Description |
  | - | - | - |
  | `command` | string | The command that was executed |
  | `result` | json | The result of the Redis command |
</ReferenceDetails>

### Upstash Redis HSET [#upstash-redis-hset]

Set a field in a hash stored at a key in Upstash Redis.

<ReferenceDetails>
  #### Input [#input-5]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The hash key |
  | `field` | string | Yes | The field name within the hash |
  | `value` | string | Yes | The value to store in the hash field |

  #### Output [#output-5]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The hash key |
  | `field` | string | The field that was set |
  | `result` | number | Number of new fields added (0 if field was updated, 1 if new) |
</ReferenceDetails>

### Upstash Redis HGET [#upstash-redis-hget]

Get the value of a field in a hash stored at a key in Upstash Redis.

<ReferenceDetails>
  #### Input [#input-6]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The hash key |
  | `field` | string | Yes | The field name to retrieve |

  #### Output [#output-6]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The hash key |
  | `field` | string | The field that was retrieved |
  | `value` | json | The value of the hash field (string), or null if not found |
</ReferenceDetails>

### Upstash Redis HGETALL [#upstash-redis-hgetall]

Get all fields and values of a hash stored at a key in Upstash Redis.

<ReferenceDetails>
  #### Input [#input-7]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The hash key |

  #### Output [#output-7]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The hash key |
  | `fields` | object | All field-value pairs in the hash, keyed by field name |
  | `fieldCount` | number | Number of fields in the hash |
</ReferenceDetails>

### Upstash Redis INCR [#upstash-redis-incr]

Atomically increment the integer value of a key by one in Upstash Redis. If the key does not exist, it is set to 0 before incrementing.

<ReferenceDetails>
  #### Input [#input-8]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to increment |

  #### Output [#output-8]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that was incremented |
  | `value` | number | The new value after incrementing |
</ReferenceDetails>

### Upstash Redis EXPIRE [#upstash-redis-expire]

Set a timeout on a key in Upstash Redis. After the timeout, the key is deleted.

<ReferenceDetails>
  #### Input [#input-9]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to set expiration on |
  | `seconds` | number | Yes | Timeout in seconds |

  #### Output [#output-9]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that expiration was set on |
  | `result` | number | 1 if the timeout was set, 0 if the key does not exist |
</ReferenceDetails>

### Upstash Redis TTL [#upstash-redis-ttl]

Get the remaining time to live of a key in Upstash Redis. Returns -1 if the key has no expiration, -2 if the key does not exist.

<ReferenceDetails>
  #### Input [#input-10]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to check TTL for |

  #### Output [#output-10]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key checked |
  | `ttl` | number | Remaining TTL in seconds. Positive integer if the key has a TTL set, -1 if the key exists with no expiration, -2 if the key does not exist. |
</ReferenceDetails>

### Upstash Redis LPUSH [#upstash-redis-lpush]

Prepend a value to the beginning of a list in Upstash Redis. Creates the list if it does not exist.

<ReferenceDetails>
  #### Input [#input-11]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The list key |
  | `value` | string | Yes | The value to prepend to the list |

  #### Output [#output-11]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The list key |
  | `length` | number | The length of the list after the push |
</ReferenceDetails>

### Upstash Redis LRANGE [#upstash-redis-lrange]

Get a range of elements from a list in Upstash Redis. Use 0 and -1 for start and stop to get all elements.

<ReferenceDetails>
  #### Input [#input-12]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The list key |
  | `start` | number | Yes | Start index (0-based, negative values count from end) |
  | `stop` | number | Yes | Stop index (inclusive, -1 for last element) |

  #### Output [#output-12]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The list key |
  | `values` | array | List of elements in the specified range |
  | `count` | number | Number of elements returned |
</ReferenceDetails>

### Upstash Redis EXISTS [#upstash-redis-exists]

Check if a key exists in Upstash Redis. Returns true if the key exists, false otherwise.

<ReferenceDetails>
  #### Input [#input-13]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to check |

  #### Output [#output-13]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that was checked |
  | `exists` | boolean | Whether the key exists (true) or not (false) |
</ReferenceDetails>

### Upstash Redis SETNX [#upstash-redis-setnx]

Set the value of a key only if it does not already exist. Returns true if the key was set, false if it already existed.

<ReferenceDetails>
  #### Input [#input-14]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to set |
  | `value` | string | Yes | The value to store if the key does not exist |

  #### Output [#output-14]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that was attempted to set |
  | `wasSet` | boolean | Whether the key was set (true) or already existed (false) |
</ReferenceDetails>

### Upstash Redis INCRBY [#upstash-redis-incrby]

Increment the integer value of a key by a given amount. Use a negative value to decrement. If the key does not exist, it is set to 0 before the operation.

<ReferenceDetails>
  #### Input [#input-15]

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `restUrl` | string | Yes | Upstash Redis REST URL |
  | `restToken` | string | Yes | Upstash Redis REST Token |
  | `key` | string | Yes | The key to increment |
  | `increment` | number | Yes | Amount to increment by (use negative value to decrement) |

  #### Output [#output-15]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that was incremented |
  | `value` | number | The new value after incrementing |
</ReferenceDetails>
