package main

import (
	"fmt"
	"git.quantgroup.cn/DevOps/enoch/service/conf"
	"github.com/gomodule/redigo/redis"
	"strconv"
)

func main() {

	pool := conf.TempNewPool()

	conn := pool.Get()
	defer func() { _ = conn.Close() }()
	del(conn)

	//var port string
	//var quartz bool
	//flag.StringVar(&port, "port", "9091", "端口")
	//flag.BoolVar(&quartz, "quartz", false, "quartz")
	//flag.Parse()
	//
	//file, err := os.Create("quantgroup.log")
	//defer func() { _ = file.Close() }()
	//if err != nil {
	//	log.Fatalln("create file error", err)
	//}
	//
	//logger := log.New(file, "[Info]", log.LstdFlags|log.Llongfile)
	//
	//logger.Println("项目启动" + port)
	//defer logger.Println("项目结束")
	//
	////初始化redis连接池
	//conf.RedisPoolInit()
	//
	//go service.Consumer()
	//
	//if quartz {
	//	log.Println("启动定时任务")
	//	job.AutoEmailPerformInfo()
	//}
	//
	//http.HandleFunc("/duration", service.DurationInterface)
	//http.HandleFunc("/counter", service.CounterInterface)
	//
	//err = http.ListenAndServe(":"+port, nil)
	//if err != nil {
	//	log.Fatalln("服务启动失败", err)
	//}

}

func del(conn redis.Conn) {
	for i := 0; ; {
		matchPattern := "SMS_Phone_verification_code_count:1*"
		reply, err := redis.Values(conn.Do("scan", i, "match", matchPattern, "count", 10000))
		if err != nil {
			fmt.Print("Scan 扫描key出错", err)
		}

		i, err = strconv.Atoi(string(reply[0].([]uint8)))

		if i == 0 {
			fmt.Print("执行全部成功.")
			return
		}
		fmt.Println(i)

		redisKeys := reply[1].([]interface{})
		var keys redis.Args
		for _, redisKey := range redisKeys {
			keys = keys.AddFlat(redisKey)
			//keys = append(keys, string(redisKey.([]uint8)))
		}
			bil, err := redis.Bool(conn.Do("del", keys))
			if err != nil {
				fmt.Print(err)
			}
				fmt.Println(bil)
		//err = conn.Send("del", reply[1])
		//if err != nil {
		//	fmt.Print(err)
		//}

		fmt.Println("执行成功.")
	}
}
