Skip to main content

Redis - AI Rooms Workflow Addon

Overview

Redis key-value storage addon for Rooms AI, providing fast in-memory data storage and caching capabilities.

Addon Type: redis ( 'storage' type addon )

Features

  • Set Key: Store string values in Redis with optional expiration
  • Get Key: Retrieve values from Redis by key
  • Delete Key: Remove keys from Redis
  • List Keys: Find keys matching a pattern
  • Connection Management: Automatic Redis connection handling with SSL support
  • Credential Management: Secure password handling via environment variables

Add to Rooms AI using poetry

Using the script

poetry add git+https://github.com/Nexroo-ai/redis-rooms-pkg.git

In the web interface, follow online guide for adding an addon. You can still use JSON in web interface.

Configuration

Addon Configuration

Add this addon to your AI Rooms workflow configuration:

{
"addons": [
{
"id": "redis-cache",
"type": "redis",
"name": "Redis Cache",
"enabled": true,
"config": {
"host": "localhost",
"port": 6379,
"db": 0,
"ssl": false,
"decode_responses": true,
"socket_timeout": 5,
"socket_connect_timeout": 5
},
"secrets": {
"redis_password": "REDIS_PASSWORD"
}
}
]
}

Configuration Fields

BaseAddonConfig Fields

All addons inherit these base configuration fields:

FieldTypeRequiredDefaultDescription
idstringYes-Unique identifier for the addon instance
typestringYes-Type of the addon ("redis")
namestringYes-Display name of the addon
descriptionstringYes-Description of the addon
enabledbooleanNotrueWhether the addon is enabled

CustomAddonConfig Fields (redis-specific)

This redis addon adds these specific configuration fields:

FieldTypeRequiredDefaultDescription
hoststringNo"localhost"Redis server host
portintegerNo6379Redis server port
dbintegerNo0Redis database number
usernamestringNonullRedis username (optional)
sslbooleanNofalseUse SSL connection
decode_responsesbooleanNotrueDecode responses to strings
socket_timeoutintegerNo5Socket timeout in seconds
socket_connect_timeoutintegerNo5Socket connect timeout in seconds

Required Secrets

Secret KeyEnvironment VariableDescription
redis_passwordREDIS_PASSWORDRedis server password

Environment Variables

Create a .env file in your workflow directory:

# .env file
REDIS_PASSWORD=your_redis_password_here

Available Actions

set_key

Store a string value in Redis with optional expiration time.

Parameters:

  • key (string, required): Redis key to set
  • value (string, required): Value to store
  • ex (integer, optional): Expiration time in seconds

Output Structure:

  • key (string): Redis key that was set
  • success (boolean): Whether the operation was successful
  • message (string): Status message

Workflow Usage:

{
"id": "store-session",
"name": "Store Session Data",
"action": "redis-cache::set_key",
"parameters": {
"key": "session:{{payload.user_id}}",
"value": "{{payload.session_data}}",
"ex": 3600
}
}

get_key

Retrieve a value from Redis by key.

Parameters:

  • key (string, required): Redis key to get

Output Structure:

  • key (string): Redis key that was retrieved
  • value (string): Value stored at the key
  • found (boolean): Whether the key was found
  • message (string): Status message

Workflow Usage:

{
"id": "retrieve-session",
"name": "Retrieve Session Data",
"action": "redis-cache::get_key",
"parameters": {
"key": "session:{{payload.user_id}}"
}
}

delete_key

Remove a key from Redis.

Parameters:

  • key (string, required): Redis key to delete

Output Structure:

  • key (string): Redis key that was deleted
  • deleted (boolean): Whether the key was deleted
  • message (string): Status message

Workflow Usage:

{
"id": "clear-session",
"name": "Clear Session Data",
"action": "redis-cache::delete_key",
"parameters": {
"key": "session:{{payload.user_id}}"
}
}

list_keys

Find all keys matching a pattern.

Parameters:

  • pattern (string, optional): Pattern to match keys (default: "*")

Output Structure:

  • keys (array): List of keys matching the pattern
  • count (integer): Number of keys found
  • message (string): Status message

Workflow Usage:

{
"id": "list-sessions",
"name": "List All Sessions",
"action": "redis-cache::list_keys",
"parameters": {
"pattern": "session:*"
}
}

Common Use Cases

Caching API Responses

{
"steps": [
{
"id": "check-cache",
"action": "redis-cache::get_key",
"parameters": {
"key": "api:response:{{payload.request_id}}"
}
},
{
"id": "fetch-api",
"condition": "{{check-cache.output.found}} == false",
"action": "external-api::fetch",
"parameters": {
"endpoint": "{{payload.endpoint}}"
}
},
{
"id": "store-cache",
"condition": "{{check-cache.output.found}} == false",
"action": "redis-cache::set_key",
"parameters": {
"key": "api:response:{{payload.request_id}}",
"value": "{{fetch-api.output.response}}",
"ex": 300
}
}
]
}

Session Management

{
"steps": [
{
"id": "create-session",
"action": "redis-cache::set_key",
"parameters": {
"key": "session:{{payload.user_id}}",
"value": "{{payload.session_token}}",
"ex": 86400
}
},
{
"id": "verify-session",
"action": "redis-cache::get_key",
"parameters": {
"key": "session:{{payload.user_id}}"
}
}
]
}

Testing & Lint

Like all Rooms AI deployments, addons should be roughly tested.

A basic PyTest is setup with a cicd to require 90% coverage in tests. Else it will not deploy the new release.

We also have ruff set up in cicd.

Running the Tests

poetry run pytest tests/ --cov=src/redis_rooms_pkg --cov-report=term-missing

Running the linter

poetry run ruff check . --fix

Pull Requests & versioning

Like for all deployments, we use semantic versioning in cicd to automatize the versions.

For this, use the apprioriate commit message syntax for semantic release in github.

Developers / Mainteners