golang定时器与redis结合,每隔1秒ping一下,每隔20秒llen一下队列的长度
package main import ( "fmt" "time" "github.com/go-redis/redis" ) var ( client *redis.Client ) func main() { client = redis.NewClient(&redis.Options{ Addr: "xxx:xxxx", Password: "", DB: 0, }) t := time.NewTicker(time.Second) t1 := time.NewTicker(time.Second * 20) for { select { case <-t.C: pong, _ := client.Ping().Result() fmt.Println(pong) case <-t1.C: num, _ := client.LLen("ent_imap_lz").Result() fmt.Println("队列数量", num) } } }