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:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
id | string | Yes | - | Unique identifier for the addon instance |
type | string | Yes | - | Type of the addon ("redis") |
name | string | Yes | - | Display name of the addon |
description | string | Yes | - | Description of the addon |
enabled | boolean | No | true | Whether the addon is enabled |
CustomAddonConfig Fields (redis-specific)
This redis addon adds these specific configuration fields:
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
host | string | No | "localhost" | Redis server host |
port | integer | No | 6379 | Redis server port |
db | integer | No | 0 | Redis database number |
username | string | No | null | Redis username (optional) |
ssl | boolean | No | false | Use SSL connection |
decode_responses | boolean | No | true | Decode responses to strings |
socket_timeout | integer | No | 5 | Socket timeout in seconds |
socket_connect_timeout | integer | No | 5 | Socket connect timeout in seconds |
Required Secrets
| Secret Key | Environment Variable | Description |
|---|---|---|
redis_password | REDIS_PASSWORD | Redis 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 setvalue(string, required): Value to storeex(integer, optional): Expiration time in seconds
Output Structure:
key(string): Redis key that was setsuccess(boolean): Whether the operation was successfulmessage(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 retrievedvalue(string): Value stored at the keyfound(boolean): Whether the key was foundmessage(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 deleteddeleted(boolean): Whether the key was deletedmessage(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 patterncount(integer): Number of keys foundmessage(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
- Adrien EPPLING : adrienesofts@gmail.com