How whatyouhide/redix works
Project type and purpose
• Type: an open-source Elixir library (Redis client)
• Purpose: provide a fast, pipelined, resilient interface for sending commands and Pub/Sub messages to Redis (including support for SSL and Sentinel)
File structure
• Top-level files: mix.exs (project config), docker-compose.yml (test harness), pages/ (extended docs), lib/redix/ (source code), test/ (unit & integration tests with Docker)
• lib/redix/ contains:
– connection.ex (GenServer that manages one Redis connection)
– connector.ex (module to open TCP/SSL sockets, handle reconnections)
– protocol.ex (encode/decode RESP wire protocol)
– format.ex (translate Elixir command lists to RESP frames)
– socket_owner.ex (process that exclusively owns the socket)
– start_options.ex (validate and normalize user options)
– uri.ex (parse Redis & Sentinel URIs)
– telemetry.ex (emit events for command latencies, errors, reconnections)
– exceptions.ex (custom error types)
– pubsub/ folder (Redix.PubSub implementation, separate connection, subscribe/publish logic)
• test/docker/ defines Redis & Sentinel setups used by the test suite (ACL, auth, sentinel scenarios)
Inspect the README for additional insights
• Describes features: pipelining, automatic reconnection with backoff, Pub/Sub, SSL, Sentinel support
• Usage: Redix.start_link / Redix.command / Redix.pipeline / Redix.PubSub APIs
• Advises using docker-compose for spinning up Redis instances when running tests
Main components
• Redis primary instance
• Zero or more Redis replicas
• Sentinel cluster (one or more instances)
• Redix Connection GenServer
– uses Connector → opens TCP/SSL socket to Redis or Sentinel
– uses Protocol & Format to encode/decode commands & replies
– owns a socket via SocketOwner process
– publishes metrics via Telemetry
• Redix.PubSub GenServer (similar structure to Connection, but handles subscription messages and incoming events)
• Top-level Supervisor
– children: Connection processes, PubSub processes
• User API → Connection GenServer : call Redix.command/2 or pipeline/2
• Connection → Connector : socket_open(host, port, opts)
• Connector → TCP/SSL socket : connect, send binary frames
• Connection → Protocol.decode(stream) : parse RESP replies
• Connection → Telemetry : emit start/stop events, errors, reconnections
• PubSub GenServer ↔ Redis server : SUBSCRIBE commands & async message pushes
• Connection on disconnect → Connector : retry with exponential backoff
• When using Sentinel → Connector contacts Sentinel URIs → sends SENTINEL get-master-addr-by-name → discovers primary → (re)connects to primary
Architectural patterns & design principles
• OTP supervision: each connection and PubSub runs under a supervisor for automatic restart
• Separation of concerns: connector (transport), protocol (wire format), format (command shaping), telemetry (metrics)
• Resiliency: built-in reconnection strategy with configurable backoff
• Extensibility: start_options and URI parsing allow plugging SSL or custom transports