|
|
@@ -1,6 +1,8 @@
|
|
|
package cmd
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
+
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
"github.com/runningwater/gohub/pkg/cache"
|
|
|
@@ -18,12 +20,31 @@ var CmdCacheClear = &cobra.Command{
|
|
|
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)
|
|
|
+ CmdCache.AddCommand(CmdCacheClear, CmdCacheForget)
|
|
|
+
|
|
|
+ // 注册 forget 命令的选项
|
|
|
+ CmdCacheForget.Flags().StringVarP(&cacheKey, "key", "k", "", "Cache key")
|
|
|
+ _ = CmdCacheForget.MarkFlagRequired("key")
|
|
|
+
|
|
|
}
|