One semantic core
Decision
Implement Redis 7.2.4 command semantics once in the pg_redis PostgreSQL 18 C extension, and use the pgredis Go gateway strictly for wire-protocol framing, TLS, authentication, session queues and connection pooling. Both RESP clients and SQL callers (redis.command, redis.command_bin) invoke the same C command core, with PostgreSQL tables and WAL as the only persistent store.
Rationale
Implementing Redis data semantics in the Go gateway would require duplicating PostgreSQL’s transaction isolation, savepoint rollback, MVCC visibility, expiry cleanup and role-permission enforcement across two processes. Putting the semantic core inside the PostgreSQL extension gives SQL table writes and Redis key mutations a single atomic commit boundary.
The Go gateway still performs essential transport work:
- Negotiating TLS and parsing RESP2 / RESP3 frames under strict memory budgets.
- Holding
MULTIcommand queues beforeEXECsubmits them in one transaction. - Driving long-lived blocking waits, Pub/Sub subscriptions, client-side caching pushes and
MONITORstreams across pooled backend connections. - Verifying commit confirmation (
ReadyForQuery) and runningredis._pool_reset()before returning connections to the pool.
Trade-offs and invariants
- Requires superuser and preload: Because
pg_redisis a C extension that registers shared memory and a background expiry worker viashared_preload_libraries, it cannot be deployed as a gateway-only proxy in front of unprivileged managed PostgreSQL services. - Database-level write locking: Protecting cross-key and cross-database Redis invariants inside SQL transactions uses a per-database exclusive lock for writes other than plain
GET/SET, trading single-database write concurrency for strict transactional consistency in0.1.0. - Non-negotiable invariants: Every performance optimization must preserve byte-exact binary keys and values, lock ordering, PostgreSQL role permission checks,
synchronous_commit = onby default, and the rule that an operation with an unknown commit outcome is never replayed.
