add Valkey configuration and connection management

This commit is contained in:
pigwin
2025-01-06 20:47:55 +00:00
parent c456bdecdb
commit c6fc0070cf
7 changed files with 163 additions and 1 deletions

26
valkey/commands.go Normal file
View File

@@ -0,0 +1,26 @@
package valkey
import (
"context"
"fmt"
"github.com/valkey-io/valkey-go"
)
func SetValkeyValue(client valkey.Client, key, value string) error {
ctx := context.Background()
err := client.Do(ctx, client.B().Set().Key(key).Value(value).Build()).Error()
if err != nil {
return fmt.Errorf("failed to set value in Valkey: %v", err)
}
return nil
}
func GetValkeyValue(client valkey.Client, key string) (string, error) {
ctx := context.Background()
value, err := client.Do(ctx, client.B().Get().Key(key).Build()).ToString()
if err != nil {
return "", fmt.Errorf("failed to get value from Valkey: %v", err)
}
return value, nil
}