File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ // Remove invalid cache entries.
4+ // Cache entry is invalid, if it contains a special substring.
5+
6+ import (
7+ "context"
8+ "log"
9+ "strings"
10+
11+ "github.com/go-redis/redis"
12+ )
13+
14+ var invalidEntrySubstr = "Unknown cheat sheet"
15+
16+ func removeInvalidEntries () error {
17+ rdb := redis .NewClient (& redis.Options {
18+ Addr : "localhost:6379" ,
19+ Password : "" ,
20+ DB : 0 ,
21+ })
22+
23+ ctx := context .Background ()
24+ allKeys , err := rdb .Keys (ctx , "*" ).Result ()
25+ if err != nil {
26+ return err
27+ }
28+
29+ var counter int
30+ for _ , key := range allKeys {
31+ val , err := rdb .Get (ctx , key ).Result ()
32+ if err != nil {
33+ return err
34+ }
35+ if strings .Contains (val , invalidEntrySubstr ) {
36+ err = rdb .Del (ctx , key ).Err ()
37+ if err != nil {
38+ return err
39+ }
40+ counter ++
41+ }
42+ }
43+ log .Println ("invalid entries removed:" , counter )
44+ return nil
45+ }
46+
47+ func main () {
48+ err := removeInvalidEntries ()
49+ if err != nil {
50+ log .Println (err )
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments