| 12345678910111213141516171819202122232425262728293031323334 |
- package redisx
- import (
- "context"
- "fmt"
- "time"
- )
- // 工具方法(Del、Expire、TTL、Exists、Scan 等)
- func Del(ctx context.Context, keys ...string) error {
- if len(keys) == 0 {
- return fmt.Errorf("no key provided")
- }
- return getClient().Del(ctx, keys...).Err()
- }
- func Expire(ctx context.Context, key string, ttl time.Duration) (bool, error) {
- return getClient().Expire(ctx, key, ttl).Result()
- }
- func ExpireAt(ctx context.Context, key string, tm time.Time) (bool, error) {
- return getClient().ExpireAt(ctx, key, tm).Result()
- }
- func TTL(ctx context.Context, key string) (time.Duration, error) {
- return getClient().TTL(ctx, key).Result()
- }
- func Exists(ctx context.Context, key string) (bool, error) {
- n, err := getClient().Exists(ctx, key).Result()
- return n > 0, err
- }
|