MCPcopy Create free account
hub / github.com/chubin/cheat.sh / removeInvalidEntries

Function removeInvalidEntries

share/scripts/cacheCleanup.go:16–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14var invalidEntrySubstr = "Unknown cheat sheet"
15
16func 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
47func main() {
48 err := removeInvalidEntries()

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected