Skip to content

feat(proto): support scanning uuid.UUID in Scan() #3425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion internal/proto/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"net"
"reflect"
"time"

"github.com/google/uuid"

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.0.x, 1.23.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.2.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.2.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.2.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.2.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (7.4.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (7.4.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (7.4.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (7.4.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.2.x, 1.23.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.0.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.0.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.0.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (8.0.x, 1.24.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / benchmark (7.4.x, 1.23.x)

no required module provides package github.com/google/uuid; to add it:

Check failure on line 9 in internal/proto/scan.go

View workflow job for this annotation

GitHub Actions / build (1.24.x, 7.4.2-54)

no required module provides package github.com/google/uuid; to add it:
"github.com/redis/go-redis/v9/internal/util"
)

Expand All @@ -23,6 +23,14 @@
case *[]byte:
*v = b
return nil
case *uuid.UUID:
str := util.BytesToString(b)
u, err := uuid.Parse(str)
if err != nil {
return fmt.Errorf("redis: failed to parse uuid: %w", err)
}
*v = u
return nil
case *int:
var err error
*v, err = util.Atoi(b)
Expand Down Expand Up @@ -120,6 +128,7 @@
case *net.IP:
*v = b
return nil

default:
return fmt.Errorf(
"redis: can't unmarshal %T (consider implementing BinaryUnmarshaler)", v)
Expand Down
20 changes: 20 additions & 0 deletions internal/proto/test_scanuuid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package proto

import (
"github.com/google/uuid"
"testing"
)

func TestScanUUID(t *testing.T) {
u1 := uuid.New()
var u2 uuid.UUID

err := Scan([]byte(u1.String()), &u2)
if err != nil {
t.Fatalf("Scan failed: %v", err)
}

if u1 != u2 {
t.Errorf("UUID mismatch, got %v, want %v", u2, u1)
}
}
Loading