Skip to content

Architecture

Gateway, extension and storage: how one semantic core serves RESP and SQL.

pgredis is a service API protocol consisting of two components running on stock PostgreSQL 18:

  • pgredis (Go gateway): accepts Redis client connections over TCP/TLS, parses RESP2 and RESP3 frames, handles authentication, maintains MULTI queues and session state, and manages per-identity PostgreSQL connection pools. Current source uses pgx v5.12.0 with a local read-budget patch; the v0.1.0-rc1 packages use v5.11.0.
  • pg_redis (PostgreSQL 18 C extension): implements Redis 7.2.4 standalone command semantics in schema redis, enforces privileges and lock order, runs a background expiry worker via shared_preload_libraries, and stores all keys in ordinary WAL-logged PostgreSQL tables.

SQL callers (redis.command and redis.command_bin) invoke the same C core directly inside their own PostgreSQL transaction.

flowchart LR
  Client["Redis client (RESP2 / RESP3)"] --> Gateway["pgredis Go gateway"]
  Gateway --> Core["pg_redis C extension"]
  SQL["SQL transaction (redis.command)"] --> Core
  Core --> Tables["PostgreSQL 18 tables and WAL"]

Component responsibilities

ComponentResponsibilities
pgredis Go gatewayRESP2/RESP3 framing, TLS termination, authentication (native and redis-acl), MULTI command queueing, blocking/Pub/Sub polling, output buffer budgets and pooled connection reset
pg_redis C extensionCommand execution, capability checks, database and key locking, binary key/member lookup, lazy and background expiry, tracking invalidation and MONITOR staging
PostgreSQL 18ACID transactions, write-ahead log (WAL), crash recovery, physical/logical backup and streaming replication

Section contents

  • Request path — how a RESP frame executes in a PostgreSQL transaction, commits, and resets its pooled backend connection.
  • Storage — the redis.* tables behind keys, collections, Streams, Pub/Sub, blocking waits and metadata.
  • Session lifecycle — how blocking operations, Pub/Sub subscriptions, expired keys and pooled connections are managed and cleaned up.

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

The tables behind each Redis data type and how keys, expiry and streams are stored.

Connections, authentication, pooled sessions, blocking commands and subscriptions over time.