MCPcopy
hub / github.com/redis/go-redis / main

Function main

example/del-keys-without-ttl/main.go:14–40  ·  example/del-keys-without-ttl/main.go::main
()

Source from the content-addressed store, hash-verified

12)
13
14func main() {
15 ctx := context.Background()
16
17 rdb := redis.NewClient(&redis.Options{
18 Addr: ":6379",
19 })
20
21 _ = rdb.Set(ctx, "key_with_ttl", "bar", time.Minute).Err()
22 _ = rdb.Set(ctx, "key_without_ttl_1", "", 0).Err()
23 _ = rdb.Set(ctx, "key_without_ttl_2", "", 0).Err()
24
25 checker := NewKeyChecker(rdb, 100)
26
27 start := time.Now()
28 checker.Start(ctx)
29
30 iter := rdb.Scan(ctx, 0, "", 0).Iterator()
31 for iter.Next(ctx) {
32 checker.Add(iter.Val())
33 }
34 if err := iter.Err(); err != nil {
35 panic(err)
36 }
37
38 deleted := checker.Stop()
39 fmt.Println("deleted", deleted, "keys", "in", time.Since(start))
40}
41
42type KeyChecker struct {
43 rdb *redis.Client

Callers

nothing calls this directly

Calls 10

StartMethod · 0.95
AddMethod · 0.95
StopMethod · 0.95
NewKeyCheckerFunction · 0.85
IteratorMethod · 0.80
ErrMethod · 0.65
SetMethod · 0.65
ScanMethod · 0.65
NextMethod · 0.65
ValMethod · 0.45

Tested by

no test coverage detected