# Request path

> From a RESP frame to a committed PostgreSQL transaction and back to the client.

---

LLMS index: [llms.txt](/llms.txt)

---

For an ordinary command outside `MULTI`, the gateway executes the command inside a PostgreSQL transaction and waits for PostgreSQL to confirm the commit before writing the RESP reply to the client.

## Ordinary command sequence {#ordinary}

1. The gateway parses the incoming RESP2 or RESP3 frame and enforces request-header and argument-size budgets.
2. The gateway acquires a pooled PostgreSQL connection bound to the authenticated identity.
3. The `pg_redis` extension verifies function ownership and role capabilities (`redis._read()`, `redis._write()`, `redis._admin()`) and acquires the required database and key locks.
4. The extension takes a current snapshot and runs the C command handler against the `redis.*` tables.
5. PostgreSQL commits the transaction (including a WAL flush when `synchronous_commit = on`).
6. Once the commit `ReadyForQuery` frame arrives, the gateway sends the RESP reply to the client and resets the backend connection before returning it to the pool.

If the gateway cannot confirm the commit or complete the connection reset, it closes the client and backend connections without replaying the command.

## Fast path for plain GET and SET {#single-call}

Plain `GET` and plain `SET` (without extra options) use the private `redis._dispatch_single` entry point:

- Instead of taking the per-database exclusive lock used by other write commands, eligible requests take a database-level shared lock plus a per-key exclusive lock held until commit or rollback.
- If a command encounters a condition that requires broader coordination (such as shared integer objects, expiry handling, tracking notifications or waking a blocked client), the extension discards the cached lookup and upgrades to the standard exclusive path.
- Direct SQL calls (`redis.command` and `redis.command_bin`) join the caller's SQL transaction and do not use the gateway-only single-call entry point.

## Wire pipelining and pooled-connection reset {#sql}

On the PostgreSQL wire protocol, the gateway sends the command invocation and the connection-reset call (`redis._pool_reset()`) in a single network flush while keeping their transaction boundaries separate:

- For validated connections, ordinary `GET`/`SET` dispatch and `redis._pool_reset()` use PostgreSQL `FunctionCall` messages, each followed by its own `ReadyForQuery` response.
- The first `ReadyForQuery` must report an idle transaction state (`I`) before the gateway writes the business reply to the Redis client. If a tentative result frame precedes a commit error, the gateway suppresses the reply, closes both connections and reports an unknown-outcome error.
- The second `ReadyForQuery` confirms that `redis._pool_reset()` cleared all session-local state (temporary settings, advisory locks, notification listeners and execution context) and returned binary `true`.
- If the reset step fails after the business transaction has already committed, the gateway keeps the confirmed reply sent to the client and discards the backend connection from the pool.

---

Backlinks:

- [Architecture](/docs/redis/architecture/)
