redis
redis
Source: builtin/redis
Redis, Valkey and other wire-compatible key-value stores.
Provider configuration
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | yes | — | Connection URL: redis://[user:password@]host:6379/<db>, or rediss:// for TLS. The path selects the logical database. Pass the password through a variable or env() rather than writing it into the scenario. |
Actions
redis_command
Send one command and return its reply.
Push a job onto a queue.
action "redis_command" "enqueue" {
args = ["LPUSH", "jobs:welcome_email", jsonencode({ user_id = action.postgres_insert.user.id })]
}Attributes
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
args | any | yes | — | The command and its arguments, as a list of strings, numbers and bools. jsonencode structured values first. |
Outputs
Type: object({result=any}).
The reply as result:
| Reply | Type |
|---|---|
| simple, bulk or verbatim string | string |
| integer, double, big number | number |
| boolean | bool |
| null | null |
| array, set | tuple of converted elements |
| map | object, keys as strings |
An error reply fails the action.
redis_hset
Set fields on a hash (HSET), then its expiry when ttl is set. With no ttl, an
existing expiry is left alone, as HSET does.
Turn on feature flags for an organisation.
action "redis_hset" "flags" {
key = "flags:${action.postgres_insert.org.id}"
fields = { new_checkout = true, beta_reports = false }
}Attributes
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
fields | any | yes | — | Object of field = value. |
key | string | yes | — | The key of the hash. |
on_conflict | string | no | "update" | What to do when the key already exists: "update" sets the fields on it, "ignore" leaves it as it is. |
ttl | string | no | — | Expiry for the whole hash, as a duration like "1h". |
Outputs
Type: object({created=bool,key=string,new_fields=list(string)}).
| Field | Type | Description |
|---|---|---|
key | string | The key. |
created | bool | Whether the hash was new. |
new_fields | list(string) | Fields the action added, sorted. Empty when nothing was written. |
redis_set
Store a value under a key (SET). With no ttl, any existing expiry is cleared,
as SET does.
Seed a session for a user, expiring in an hour.
action "redis_set" "session" {
key = "session:${var.token}"
value = { user_id = action.postgres_insert.user.id, roles = ["admin"] }
ttl = "1h"
}Attributes
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
key | string | yes | — | The key. |
on_conflict | string | no | "update" | What to do when the key already exists: "update" overwrites it, "ignore" leaves it as it is (SET NX). |
ttl | string | no | — | Expiry, as a duration like "1h". |
value | any | yes | — | The value. Objects, maps, lists and tuples are stored as JSON. |
Outputs
Type: object({created=bool,key=string}).
| Field | Type | Description |
|---|---|---|
key | string | The key. |
created | bool | Whether the key was new. |
Notes
redis_setandredis_hsetare typed alternatives toredis_commandfor the two shapes most seed data takes. Values are encoded the same way for both: strings as-is, numbers as decimal strings (9.99,42), bools astrue/false, and objects, maps, lists and tuples as JSON. Null is an error.ttluses Go duration syntax ("30s","1h"), like the action-leveltimeout.- Each typed action reads what exists and writes in one
MULTI/EXEC, socreatedandnew_fieldsare exact even with other clients writing. orchard teardownundoesredis_setandredis_hsetautomatically, unless the action has its ownlifecycle { teardown { } }block or setslifecycle { managed_teardown = false }. A key the action created is deleted. An overwritten key is restored as it was, value and expiry, when an earlier action in the run created it, or withmanaged_teardown = true; otherwise an overwritten string is left as written, and an existing hash loses only the fields the action added. Keys larger than 1 MB aren’t restored.redis_commandhas no automatic teardown.redis_commandarguments are sent as text. Interpolated values aren’t escaped or quoted, but they can’t change which command runs: each list element is one argument.