This commit is contained in:
oneao committed 2026-02-26 17:31:08 +08:00
1 parent 4ce951dd56
commit 8a3dea8545
44 files changed
+1599 -30

No files matched your search

@@ -0,0 +1,40 @@
package redisx
import (
"context"
"errors"
"time"
"github.com/redis/go-redis/v9"
)
var (
Client *redis.Client
)
func Set(key string, value interface{}, expire time.Duration) error {
return Client.Set(context.Background(), key, value, expire).Err()
}
// Get 获取任意 key 的值,返回 string
func Get(key string) (string, error) {
val, err := Client.Get(context.Background(), key).Result()
if errors.Is(err, redis.Nil) {
return "", nil
}
return val, err
}
// Delete 删除任意 key
func Delete(key string) error {
return Client.Del(context.Background(), key).Err()
}
// Exists 判断 key 是否存在
func Exists(key string) (bool, error) {
cnt, err := Client.Exists(context.Background(), key).Result()
if err != nil {
return false, err
}
return cnt > 0, nil
}