ScriptsJul 18, 2026·3 min read

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.

Agent ready

Safe staging for this asset

This asset is staged first. The copied prompt tells the agent to inspect the staged files and ask before activating scripts, MCP config, or global config.

Stage only · 29/100Policy: stage
Agent surface
Any MCP/CLI agent
Kind
CLI Tool
Install
Single
Trust
Trust: Established
Entrypoint
Go-Redis Overview
Safe staging command
npx -y tokrepo@latest install 3755b7bf-8242-11f1-9bc6-00163e2b0d79 --target codex

Stages files first; activation requires review of the staged README and plan.

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

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets