# Go-Redis — Type-Safe Redis Client for Go > The official Go client for Redis, supporting all Redis commands, Sentinel, Cluster, pipelining, pub/sub, and streams with a clean type-safe API. ## Install Save as a script file and run: # Go-Redis — Type-Safe Redis Client for Go ## Quick Use ```bash go get github.com/redis/go-redis/v9 # Basic usage import "github.com/redis/go-redis/v9" rdb := redis.NewClient(&redis.Options{Addr: "localhost:6379"}) err := rdb.Set(ctx, "key", "value", 0).Err() val, err := rdb.Get(ctx, "key").Result() ``` ## 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.Options` struct: Addr, Password, DB, PoolSize, DialTimeout - For Sentinel: use `redis.NewFailoverClient` with master name and sentinel addresses - For Cluster: use `redis.NewClusterClient` with a list of seed nodes - Enable TLS by setting the `TLSConfig` field 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. ## Sources - https://github.com/redis/go-redis - https://redis.uptrace.dev/ --- Source: https://tokrepo.com/en/workflows/asset-3755b7bf Author: Script Depot