Skip to content

Instantly share code, notes, and snippets.

@dolmen
Last active March 9, 2023 17:47
Show Gist options
  • 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
#!/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