38 lines
780 B
Go
38 lines
780 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
func HGetAll(ctx context.Context, key string) (map[string]string, error) {
|
|
kvs, err := client.HGetAll(ctx, key).Result()
|
|
if err == redis.Nil {
|
|
return nil, nil
|
|
} else if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return kvs, nil
|
|
}
|
|
|
|
func HMSet(ctx context.Context, key string, fields map[string]interface{}) error {
|
|
return client.HMSet(ctx, key, fields).Err()
|
|
}
|
|
|
|
func HGet(ctx context.Context, key, field string) (string, error) {
|
|
v, err := client.HGet(ctx, key, field).Result()
|
|
if err == redis.Nil {
|
|
return "", nil
|
|
} else if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return v, nil
|
|
}
|
|
|
|
func HSet(ctx context.Context, key, field string, value interface{}) error {
|
|
return client.HSet(ctx, key, field, value).Err()
|
|
}
|