Files
assets/cmd/clear_cache/main.go
2026-03-18 10:18:03 +08:00

45 lines
788 B
Go

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)
}