| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package cmd
- import (
- "fmt"
- "github.com/spf13/cobra"
- "github.com/runningwater/gohub/pkg/cache"
- "github.com/runningwater/gohub/pkg/console"
- )
- var CmdCache = &cobra.Command{
- Use: "cache",
- Short: "Cache Management",
- }
- var CmdCacheClear = &cobra.Command{
- Use: "clear",
- Short: "Clear Cache",
- Run: runCacheClear,
- }
- var CmdCacheForget = &cobra.Command{
- Use: "forget",
- Short: "Delete redis key, example: gohub cache forget key",
- Run: runCacheForget,
- }
- func runCacheClear(cmd *cobra.Command, args []string) {
- cache.Flush()
- console.Success("Cache cleared")
- }
- func runCacheForget(cmd *cobra.Command, args []string) {
- cache.Forget(cacheKey)
- console.Success(fmt.Sprintf("Cache key [%s] deleted", cacheKey))
- }
- // forget 命令的选项
- var cacheKey string
- func init() {
- // 注册 cache 命令的子命令
- CmdCache.AddCommand(CmdCacheClear, CmdCacheForget)
- // 注册 forget 命令的选项
- CmdCacheForget.Flags().StringVarP(&cacheKey, "key", "k", "", "Cache key")
- _ = CmdCacheForget.MarkFlagRequired("key")
- }
|