Request path
From a RESP frame to a committed PostgreSQL transaction and back to the client.
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
- The gateway parses the incoming RESP2 or RESP3 frame and enforces request-header and argument-size budgets.
- The gateway acquires a pooled PostgreSQL connection bound to the authenticated identity.
- The
pg_redisextension verifies function ownership and role capabilities (redis._read(),redis._write(),redis._admin()) and acquires the required database and key locks. - The extension takes a current snapshot and runs the C command handler against the
redis.*tables. - PostgreSQL commits the transaction (including a WAL flush when
synchronous_commit = on). - Once the commit
ReadyForQueryframe 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
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.commandandredis.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
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/SETdispatch andredis._pool_reset()use PostgreSQLFunctionCallmessages, each followed by its ownReadyForQueryresponse. - The first
ReadyForQuerymust 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
ReadyForQueryconfirms thatredis._pool_reset()cleared all session-local state (temporary settings, advisory locks, notification listeners and execution context) and returned binarytrue. - 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.
