# Redis (/integrations/redis)





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

Use [Redis](https://redis.io/) in Sim through a direct connection to a Redis instance. Workflows can read and write keys, work with hashes and lists, increment values, set expiration times, and run commands.

{/* MANUAL-CONTENT-END */}

## Use the block [#usage-instructions]

Connect to any Redis instance to perform key-value, hash, list, and utility operations via a direct connection.

## Actions [#actions]

### Redis Get [#redis-get]

Get the value of a key from Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The key to retrieve |

  #### Output [#output]

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

### Redis Set [#redis-set]

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

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `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>

### Redis Delete [#redis-delete]

Delete a key from Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `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>

### Redis Keys [#redis-keys]

List all keys matching a pattern in Redis. Avoid using on large databases in production; use the Redis Command tool with SCAN for large key spaces.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `pattern` | string | No | Pattern to match keys (default: \* 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>

### Redis Command [#redis-command]

Execute a raw Redis command as a JSON array (e.g. \["HSET", "key", "field", "value"]).

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `command` | string | Yes | Redis command as a JSON array (e.g. \["SET", "key", "value"]) |

  #### Output [#output-4]

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

### Redis HSET [#redis-hset]

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

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The hash key |
  | `field` | string | Yes | The field name within the hash |
  | `value` | string | Yes | The value to set for the field |

  #### Output [#output-5]

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

### Redis HGET [#redis-hget]

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

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `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` | string | The field value, or null if the field or key does not exist |
</ReferenceDetails>

### Redis HGETALL [#redis-hgetall]

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

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `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 as a key-value object. Empty object if the key does not exist. |
  | `fieldCount` | number | Number of fields in the hash |
</ReferenceDetails>

### Redis HDEL [#redis-hdel]

Delete a field from a hash stored at a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The hash key |
  | `field` | string | Yes | The field name to delete |

  #### Output [#output-8]

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

### Redis INCR [#redis-incr]

Increment the integer value of a key by one in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The key to increment |

  #### Output [#output-9]

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

### Redis INCRBY [#redis-incrby]

Increment the integer value of a key by a given amount in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The key to increment |
  | `increment` | number | Yes | Amount to increment by (negative to decrement) |

  #### Output [#output-10]

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

### Redis EXPIRE [#redis-expire]

Set an expiration time (in seconds) on a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The key to set expiration on |
  | `seconds` | number | Yes | Timeout in seconds |

  #### Output [#output-11]

  | 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>

### Redis TTL [#redis-ttl]

Get the remaining time to live (in seconds) of a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The key to check TTL for |

  #### Output [#output-12]

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

### Redis PERSIST [#redis-persist]

Remove the expiration from a key in Redis, making it persist indefinitely.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The key to persist |

  #### Output [#output-13]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The key that was persisted |
  | `result` | number | 1 if the expiration was removed, 0 if the key does not exist or has no expiration |
</ReferenceDetails>

### Redis LPUSH [#redis-lpush]

Prepend a value to a list stored at a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The list key |
  | `value` | string | Yes | The value to prepend |

  #### Output [#output-14]

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

### Redis RPUSH [#redis-rpush]

Append a value to the end of a list stored at a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The list key |
  | `value` | string | Yes | The value to append |

  #### Output [#output-15]

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

### Redis LPOP [#redis-lpop]

Remove and return the first element of a list stored at a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The list key |

  #### Output [#output-16]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The list key |
  | `value` | string | The removed element, or null if the list is empty |
</ReferenceDetails>

### Redis RPOP [#redis-rpop]

Remove and return the last element of a list stored at a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The list key |

  #### Output [#output-17]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The list key |
  | `value` | string | The removed element, or null if the list is empty |
</ReferenceDetails>

### Redis LLEN [#redis-llen]

Get the length of a list stored at a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The list key |

  #### Output [#output-18]

  | Parameter | Type | Description |
  | - | - | - |
  | `key` | string | The list key |
  | `length` | number | The length of the list, or 0 if the key does not exist |
</ReferenceDetails>

### Redis LRANGE [#redis-lrange]

Get a range of elements from a list stored at a key in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The list key |
  | `start` | number | Yes | Start index (0-based) |
  | `stop` | number | Yes | Stop index (-1 for all elements) |

  #### Output [#output-19]

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

### Redis EXISTS [#redis-exists]

Check if a key exists in Redis.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The key to check |

  #### Output [#output-20]

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

### Redis SETNX [#redis-setnx]

Set the value of a key in Redis only if the key does not already exist.

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

  | Parameter | Type | Required | Description |
  | - | - | - | - |
  | `url` | string | Yes | Redis connection URL (e.g. redis\://user:password\@host:port) |
  | `key` | string | Yes | The key to set |
  | `value` | string | Yes | The value to store |

  #### Output [#output-21]

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