28 lines
584 B
Go
28 lines
584 B
Go
package redisx
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Set 设置 key
|
|
func Set(ctx context.Context, key string, value any, ttl time.Duration) error {
|
|
return Client().Set(ctx, key, value, ttl).Err()
|
|
}
|
|
|
|
// Get 获取 string
|
|
func Get(ctx context.Context, key string) (string, error) {
|
|
return Client().Get(ctx, key).Result()
|
|
}
|
|
|
|
// Del 删除
|
|
func Del(ctx context.Context, keys ...string) error {
|
|
return Client().Del(ctx, keys...).Err()
|
|
}
|
|
|
|
// Exists 是否存在
|
|
func Exists(ctx context.Context, key string) (bool, error) {
|
|
n, err := Client().Exists(ctx, key).Result()
|
|
return n > 0, err
|
|
}
|