From 25b4aa98ba1a00770e9e8fd8e3d9641c7f50b537 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Wed, 21 May 2025 14:59:42 +0100 Subject: [PATCH] feat: valkey schema support Add support for valkey schema in Redis client. Fixes: #688 --- redis/conn.go | 7 +++++-- redis/conn_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/redis/conn.go b/redis/conn.go index 753644b1..dc445a06 100644 --- a/redis/conn.go +++ b/redis/conn.go @@ -332,7 +332,10 @@ func DialURLContext(ctx context.Context, rawurl string, options ...DialOption) ( return nil, err } - if u.Scheme != "redis" && u.Scheme != "rediss" { + switch u.Scheme { + case "redis", "rediss", "valkey", "valkeys": + // valid scheme + default: return nil, fmt.Errorf("invalid redis URL scheme: %s", u.Scheme) } @@ -386,7 +389,7 @@ func DialURLContext(ctx context.Context, rawurl string, options ...DialOption) ( return nil, fmt.Errorf("invalid database: %s", u.Path[1:]) } - options = append(options, DialUseTLS(u.Scheme == "rediss")) + options = append(options, DialUseTLS(u.Scheme == "rediss" || u.Scheme == "valkeys")) return DialContext(ctx, "tcp", address, options...) } diff --git a/redis/conn_test.go b/redis/conn_test.go index b94f0f42..414b7ef3 100644 --- a/redis/conn_test.go +++ b/redis/conn_test.go @@ -624,6 +624,22 @@ var dialErrors = []struct { "redis:foo//localhost:6379", "invalid redis URL, url is opaque: redis:foo//localhost:6379", }, + { + "valkey://localhost:6379/abc123", + "invalid database: abc123", + }, + { + "valkeys://localhost:6379/abc123", + "invalid database: abc123", + }, + { + "valkey:foo//localhost:6379", + "invalid redis URL, url is opaque: valkey:foo//localhost:6379", + }, + { + "valkeys:foo//localhost:6379", + "invalid redis URL, url is opaque: valkeys:foo//localhost:6379", + }, } func TestDialURLErrors(t *testing.T) {