Introduction
Go-Redis is the official Redis client library for Go, maintained under the redis GitHub organization. It provides a comprehensive, type-safe API that covers every Redis command while keeping the developer experience clean and idiomatic to Go.
What Go-Redis Does
- Connects to standalone Redis, Sentinel, and Cluster deployments with automatic failover
- Supports pipelining and transactions for batching commands and reducing round trips
- Implements Pub/Sub, Streams, and scripting with Lua for event-driven architectures
- Provides connection pooling with configurable size, timeouts, and health checks
- Offers OpenTelemetry instrumentation for distributed tracing out of the box
Architecture Overview
Go-Redis uses a connection pool managed per client instance. Commands are marshaled into the RESP protocol and sent over TCP. In cluster mode, the client maintains a slot-to-node mapping and routes commands automatically, handling MOVED and ASK redirections transparently. Pipelines batch multiple commands into a single write, and the client decodes responses in order.
Self-Hosting & Configuration
- Install via
go get github.com/redis/go-redis/v9— no CGO required - Configure connection with
redis.Optionsstruct: Addr, Password, DB, PoolSize, DialTimeout - For Sentinel: use
redis.NewFailoverClientwith master name and sentinel addresses - For Cluster: use
redis.NewClusterClientwith a list of seed nodes - Enable TLS by setting the
TLSConfigfield in options
Key Features
- Full Redis command coverage including modules like RedisJSON and RediSearch
- Type-safe results — each command returns a typed result object, no manual casting
- Automatic reconnection and retry with configurable backoff
- Context-aware API with deadline and cancellation support
- Built-in support for Redis Streams consumer groups
Comparison with Similar Tools
- Redigo — lower-level API with manual connection management; go-redis offers connection pooling and type safety by default
- Rueidis — newer client focused on client-side caching and RESP3; go-redis has broader adoption and ecosystem
- go-redis/cache — a caching layer built on top of go-redis with local cache support
- Garnet — a Redis-compatible server by Microsoft; go-redis works as the client for it
FAQ
Q: Does go-redis support Redis 7 features? A: Yes, including client-side caching, sharded pub/sub, and functions.
Q: How does connection pooling work? A: Each client maintains a pool of connections. The default pool size is 10 per CPU. Idle connections are closed after 30 minutes.
Q: Can I use go-redis with Redis Cluster?
A: Yes, use redis.NewClusterClient. It handles slot routing, redirections, and read replicas automatically.
Q: Is go-redis thread-safe? A: Yes, a single client instance is safe for concurrent use across goroutines.