For AI agents: the complete documentation index is available at /hclapi/llms.txt, the full documentation bundle is available at /hclapi/llms-full.txt, and this page is available as Markdown at /hclapi/docs/steps/redis.md.

redis

Executes key-value commands against a Redis or Valkey connection pool. Supports cache reads, writes with TTL, key deletions, and counters.

Declaration

redis "cache_lookup" {
  connection = connection.redis.cache
  command    = "GET"
  key        = "product:${ctx.request.path.sku}"
}

Attributes

AttributeTypeRequiredDescription
labelstringyesStep identifier
connectionconnectionyesRedis connection pool reference
commandstringyesGET, SET, DEL, INCR, or EXISTS
keystringyesKey; supports dynamic string interpolation
valueanyfor SETValue to store
ttlDurationnoExpiration duration for SET

Output

steps.<name>.value contains the retrieved cache value, "OK" for SET, a count for DEL, or an integer for INCR.

Cache-aside pattern

endpoint "GET /api/v1/products/{sku}" {
  pipeline {
    redis "cache_lookup" {
      connection = connection.redis.cache
      command    = "GET"
      key        = "cache:product:${ctx.request.path.sku}"
    }

    respond {
      condition = steps.cache_lookup.value != null
      status    = 200
      headers   = { "X-Cache" = "HIT" }
      body      = json_decode(steps.cache_lookup.value)
    }

    sql "db_query" {
      connection = connection.postgres.main
      query      = "SELECT id, sku, name, price FROM products WHERE sku = @sku"
      args       = { sku = ctx.request.path.sku }
    }

    respond {
      condition = steps.db_query.rows_affected == 0
      status    = 404
      body      = { error = "Product not found" }
    }

    redis "cache_write" {
      connection = connection.redis.cache
      command    = "SET"
      key        = "cache:product:${ctx.request.path.sku}"
      value      = json_encode(steps.db_query.row)
      ttl        = "30m"
    }

    respond {
      status  = 200
      headers = { "X-Cache" = "MISS" }
      body    = steps.db_query.row
    }
  }
}