Skip to content

Instantly share code, notes, and snippets.

@dolmen
Last active March 9, 2023 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolmen/9f5b4b1892588a5a8948a7c8e116660b to your computer and use it in GitHub Desktop.
Save dolmen/9f5b4b1892588a5a8948a7c8e116660b to your computer and use it in GitHub Desktop.
go-redis v9 migration script

Automated go-redis v8 -> v9 migration

About v8 -> v9

https://redis.com/blog/go-redis-official-redis-client/

Usage:

curl https://gist.githubusercontent.com/dolmen/9f5b4b1892588a5a8948a7c8e116660b/raw/dafeeb86c5c1c1fe80499b0c652f218c3c69aebd/migrate-go-redis-v9.sh | bash
#!/usr/bin/env bash
set -euo pipefail
# Will fail if go-redis v8 is not referenced in go.mod
go list -m github.com/go-redis/redis/v8 >/dev/null
# Add v9
go get github.com/redis/go-redis/v9@latest
# Chdir to the root of the module
cd "$(go list -m -f '{{.Dir}}')"
# Migrate all Go source in the module
sed -i '' 's!"github.com/go-redis/redis/v8"!"github.com/redis/go-redis/v9"!' $(grep -l github.com/go-redis/redis/v8 $(go list -f '{{$Dir := .Dir}}{{range .GoFiles}}{{$Dir}}/{{.}} {{end}}{{range .XTestGoFiles}}{{$Dir}}/{{.}} {{end}}' ./... ) )
# Cleanup go.mod/go.sum
go mod tidy
# Build to raise migration issues. Ex: Client.SetEX -> Client.SetEx
exec go build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment