From 014f25246dfb9dee4a088ffb575c81434d5b1072 Mon Sep 17 00:00:00 2001
From: Zach Leslie <zach.leslie@grafana.com>
Date: Fri, 1 Nov 2024 18:27:20 +0000
Subject: [PATCH] Improve the readability of redis_client util method

---
 pkg/cache/redis_client.go | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/pkg/cache/redis_client.go b/pkg/cache/redis_client.go
index 6a6b5dc1eca..65f9f9a98f8 100644
--- a/pkg/cache/redis_client.go
+++ b/pkg/cache/redis_client.go
@@ -178,12 +178,7 @@ func (c *RedisClient) Close() error {
 	return c.rdb.Close()
 }
 
-// StringToBytes converts string to byte slice. (copied from vendor/github.com/go-redis/redis/v8/internal/util/unsafe.go)
+// StringToBytes reads the string header and returns a byte slice without copying.
 func StringToBytes(s string) []byte {
-	return *(*[]byte)(unsafe.Pointer(
-		&struct {
-			string
-			Cap int
-		}{s, len(s)},
-	))
+	return unsafe.Slice(unsafe.StringData(s), len(s))
 }