dataRT/data/redis/hash.go

34 lines
654 B
Go
Raw Normal View History

2025-09-19 16:17:46 +08:00
package redis
import (
"context"
"github.com/redis/go-redis/v9"
)
func HGetAll(ctx context.Context, key string) (map[string]string, error) {
hash, err := client.HGetAll(ctx, key).Result()
if err == redis.Nil {
return nil, nil
} else if err != nil {
return nil, err
}
return hash, nil
}
func HGet(ctx context.Context, key, field string) (string, error) {
str, err := client.HGet(ctx, key, field).Result()
if err == redis.Nil {
return "", nil
} else if err != nil {
return "", err
}
return str, nil
}
func HSet(ctx context.Context, key string, values map[string]interface{}) error {
return client.HSet(ctx, key, values).Err()
}