refactor: use sample code from Aiven

This commit is contained in:
2025-11-27 00:00:54 +07:00
parent 8bfbf7658a
commit 3baf0e545c
2 changed files with 5 additions and 10 deletions
+1 -1
View File
@@ -1 +1 @@
VALKEY_URL=valkey://default@127.0.0.1:6379
VALKEY_URI=valkey://default@127.0.0.1:6379
+4 -9
View File
@@ -17,20 +17,15 @@ func main() {
log.Println("Warning: .env file not found")
}
valkeyUrl, isExist := os.LookupEnv("VALKEY_URL")
valkeyURI, isExist := os.LookupEnv("VALKEY_URI")
if !isExist {
log.Fatal("Warning: VALKEY_URL not set!")
log.Fatal("Warning: VALKEY_URI not set!")
return
}
opt, err := valkey.ParseURL(valkeyUrl)
client, err := valkey.NewClient(valkey.ClientOption{InitAddress: []string{valkeyURI}})
if err != nil {
log.Fatal(err)
}
client, err := valkey.NewClient(opt)
if err != nil {
log.Fatal(err)
panic(err)
}
ctx, cancel := context.WithCancel(context.Background())