Dockerfile
This commit is contained in:
44
cmd/clear_cache/main.go
Normal file
44
cmd/clear_cache/main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
goredis "github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
rdb := goredis.NewClient(&goredis.Options{
|
||||
Addr: "192.168.3.200:6379",
|
||||
DB: 0,
|
||||
})
|
||||
defer rdb.Close()
|
||||
|
||||
patterns := []string{
|
||||
"*private_stock*",
|
||||
"*inventory_count*",
|
||||
"*private_sku*",
|
||||
"*warehouse*",
|
||||
"*zone*",
|
||||
"*location*",
|
||||
}
|
||||
|
||||
total := 0
|
||||
for _, pattern := range patterns {
|
||||
keys, err := rdb.Keys(ctx, pattern).Result()
|
||||
if err != nil {
|
||||
fmt.Printf("查询模式[%s]失败: %v\n", pattern, err)
|
||||
continue
|
||||
}
|
||||
for _, key := range keys {
|
||||
rdb.Del(ctx, key)
|
||||
total++
|
||||
}
|
||||
if len(keys) > 0 {
|
||||
fmt.Printf("✅ 模式[%s] 清除了 %d 个key\n", pattern, len(keys))
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("\n共清除 %d 个Redis缓存key\n", total)
|
||||
}
|
||||
Reference in New Issue
Block a user