migrate-go-redis
Migrating from go-redis to Valkey GLIDE (Go)
Use when migrating a Go application from go-redis/redis to the GLIDE client library.
Routing
- String, hash, list, set, sorted set, delete, exists, cluster -> API Mapping
- Pipeline, transaction, Batch API, TxPipelined -> Advanced Patterns
- PubSub, subscribe, publish, queue-based polling -> Advanced Patterns
Key Differences
| Area | go-redis | GLIDE |
|---|---|---|
| Return types | *StatusCmd, *StringCmd with .Result() |
models.Result[T] with .Value() and .IsNil() |
| Nil handling | redis.Nil sentinel error |
val.IsNil() method |
| Configuration | redis.Options{} struct |
config.NewClientConfiguration() builder chain |
| Multi-arg commands | Varargs: Del(ctx, "k1", "k2") |
Slice args: Del(ctx, []string{"k1", "k2"}) |
| Expiry | Duration arg: Set(ctx, "k", "v", 60*time.Second) |
SetWithOptions + options.SetOptions |
| Transactions | TxPipelined() closure |
pipeline.NewStandaloneBatch(true) + client.Exec() |
| Pipelines | Pipelined() closure |
pipeline.NewStandaloneBatch(false) + client.Exec() |
| Connection model | Pool with configurable size | Single multiplexed connection per node |
| API style | Synchronous with goroutine safety | Synchronous with goroutine safety (via CGO bridge) |
Error Handling - The Biggest Change
go-redis:
val, err := rdb.Get(ctx, "key").Result()
if err == redis.Nil {
fmt.Println("key does not exist")
} else if err != nil {
fmt.Println("error:", err)
} else {
fmt.Println("value:", val)
}
GLIDE:
val, err := client.Get(ctx, "key")
if err != nil {
fmt.Println("error:", err)
return
}
if val.IsNil() {
fmt.Println("key does not exist")
} else {
fmt.Println("value:", val.Value())
}
go-redis uses redis.Nil as an error sentinel for missing keys. GLIDE separates nil from errors - err is only for actual errors, val.IsNil() checks for key absence.
Quick Start - Connection Setup
go-redis:
rdb := redis.NewClient(&redis.Options{Addr: "localhost:6379", Password: "", DB: 0})
GLIDE:
cfg := config.NewClientConfiguration().
WithAddress(&config.NodeAddress{Host: "localhost", Port: 6379})
client, err := glide.NewClient(cfg)
defer client.Close()
Configuration Mapping
| go-redis field | GLIDE equivalent |
|---|---|
Addr: "host:port" |
WithAddress(&config.NodeAddress{Host, Port}) |
Password |
WithCredentials(&config.ServerCredentials{Password: "..."}) |
DB |
WithDatabaseId(0) |
DialTimeout |
WithRequestTimeout(ms) |
TLSConfig |
WithUseTLS(true) |
PoolSize |
Not needed - single multiplexed connection |
MaxRetries |
Built-in reconnection via WithReconnectStrategy |
Incremental Migration Strategy
No drop-in compatibility layer exists for Go. Migration approach:
- Add
github.com/valkey-io/valkey-glide/go/v2to yourgo.modalongsidego-redis - Define a repository or store interface that abstracts the Redis client
- Create a GLIDE implementation alongside the go-redis one
- Replace
redis.Nilerror checks withResult[T].IsNil()at each call site - Run tests after each package migration to catch nil-handling regressions
- Remove
go-redisfromgo.modonce all implementations are migrated
Reference
| Topic | File |
|---|---|
| Command-by-command API mapping (strings, hashes, lists, sets, sorted sets, delete, exists, cluster) | api-mapping |
| Transactions, pipelines, Pub/Sub, Go API maturity timeline | advanced-patterns |
See Also
- valkey-glide-go skill - full GLIDE Go API details
- Batching (see valkey-glide skill) - pipeline and transaction patterns
- PubSub (see valkey-glide skill) - subscription patterns and dynamic PubSub
Gotchas
Result[T]instead ofredis.Nil. CheckIsNil()before callingValue().- Slice args, not varargs. Multi-key commands take
[]stringslices. - Separate
SetandSetWithOptions. go-redis combines expiry intoSet(). GLIDE has separate methods. - CGO dependency. GLIDE for Go uses CGO to call the Rust core. Cross-compilation requires Docker-based builds or platform-native compilation.
- Alpine Linux / MUSL. Requires the
muslbuild tag:export GOFLAGS=-tags=musl. - No connection pool tuning. Drop all
PoolSize,MinIdleConnsconfiguration. - Import path. Module is
github.com/valkey-io/valkey-glide/go/v2with subpackagesconfig,options,pipeline,models,constants. go mod vendorsupport. Added in GLIDE 2.2 - earlier versions did not work with vendor mode.
More from avifenesh/valkey-skills
valkey
Use when building apps with Valkey - caching, sessions, queues, locks, rate-limiting, leaderboards, counters, pub-sub, streams, scripting. Covers IFEQ/DELIFEQ, hash field TTL, COMMANDLOG. Not for server internals (valkey-dev) or ops (valkey-ops).
5valkey-dev
Use when contributing to the Valkey server - C internals, event loop, commands, data structures, cluster, replication, RDB/AOF, memory, threading, modules, Lua, RESP, tests. Not for app development (valkey) or ops (valkey-ops).
5valkey-ops
Use when deploying, configuring, monitoring, or troubleshooting self-hosted Valkey. Covers Sentinel, cluster, persistence, replication, security, Kubernetes, performance tuning. Not for app development (valkey) or server internals (valkey-dev).
5valkey-ecosystem
Use when evaluating the Valkey ecosystem - client libraries, modules (JSON, Bloom, Search), managed services (AWS, GCP, Aiven), monitoring tools, frameworks (Spring, Django, Rails), Docker/Kubernetes deployment, CI/CD patterns, migration from Redis, and developer tooling.
5glide-mq
Use when building message queues with glide-mq. Covers queue setup, producer/consumer patterns, job scheduling, workflows, batch processing, streaming, and suspend/resume. Not for migrating from BullMQ (migrate-bullmq) or Bee-Queue (migrate-bee).
4valkey-glide
Router for Valkey GLIDE per-language skills. Use when you need to find the right language-specific GLIDE skill or migration skill. Not for GLIDE library internals or contributing to GLIDE source code - use glide-dev instead.
4