API Reference
go-redis
Redis client for Go with a context-aware API, pipelining, clustering, and pub/sub.
Official Documentation ↗CompatibilityThis documentation covers version
v9.6. Check the official docs for the latest API surface.Installation
go
go get github.com/redis/go-redis/v9Methods
No methods match this filter.
go-redis is a Redis client for Go. It offers a context-aware API, connection pooling, pipelining, transactions, pub/sub, Lua scripting, and cluster support with automatic routing.
Key Features
- Context-aware: Per-command deadlines and cancellation
- Pipelining & transactions: Batch for speed or atomicity
- Cluster: Automatic slot routing and failover
- Pub/sub: Channel-based messaging
- Types: Strings, hashes, lists, sets, sorted sets
Errors
The official API reference declares the following error types:
redis.Nil(const (proto.RedisError, satisfies error)) — official text: “// Nil reply returned by Redis when key does not exist. const Nil = proto.Nil” (source: https://raw.githubusercontent.com/redis/go-redis/v9.5.1/redis.go, fetched 2026-11-08T15:52:26+08:00)redis.ErrClosed(var error (pool.ErrClosed)) — official text: “// ErrClosed performs any operation on the closed client will return this error. var ErrClosed = pool.ErrClosed” (source: https://raw.githubusercontent.com/redis/go-redis/v9.5.1/error.go, fetched 2026-11-08T15:52:26+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T15:52:26+08:00 via WebFetch pkg.go.dev + PowerShell Invoke-WebRequest raw.githubusercontent.com (redis/go-redis v9.5.1).
redis.NewClient→ signature from https://raw.githubusercontent.com/redis/go-redis/v9.5.1/redis.go; official text: “// NewClient returns a client to the Redis Server specified by Options. func NewClient(opt *Options) *Client {”Set / Get→ signature from https://raw.githubusercontent.com/redis/go-redis/v9.5.1/string_commands.go; official text: “// Set RedisSET key value [expiration]command. // Use expiration forSETEx-like behavior. // // Zero expiration means the key has no expiration time. // KeepTTL is a Redis KEEPTTL option to keep existing TTL, it re”HSet / HGetAll→ signature from https://raw.githubusercontent.com/redis/go-redis/v9.5.1/string_commands.go; official text: “// Set RedisSET key value [expiration]command. // Use expiration forSETEx-like behavior. // // Zero expiration means the key has no expiration time. // KeepTTL is a Redis KEEPTTL option to keep existing TTL, it re”Pipelined→ signature from https://raw.githubusercontent.com/redis/go-redis/v9.5.1/pipeline.go; official text: “func (c *Pipeline) Pipelined(ctx context.Context, fn func(Pipeliner) error) ([]Cmder, error) {”Subscribe→ signature from https://raw.githubusercontent.com/redis/go-redis/v9.5.1/redis.go; official text: “func (c *Client) Subscribe(ctx context.Context, channels …string) *PubSub {”
FAQ
- How do I connect to a Redis Cluster?
- Use redis.NewClusterClient with a ClusterOptions containing the seed node addresses. The client handles slot routing, MOVED and ASK redirections, and failover automatically across the cluster.
- What is the difference between Pipelined and TxPipeline?
- Pipelined batches commands in one round trip without atomicity. TxPipeline wraps them in MULTI/EXEC for a transaction. Use TxPipeline when you need all commands to execute atomically.
- How does go-redis handle context and timeouts?
- Every command takes a context.Context, so you can enforce per-command deadlines and cancellation. Combine with Options.ReadTimeout and WriteTimeout for socket-level limits. Canceled contexts abort pending commands.
Report a problem with this API docOpens a pre-filled issue on GitHub.