[Go] golang定时器与redis结合

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

}
posted @ 2019-12-11 19:30  唯一客服系统开发笔记  阅读(797)  评论(0编辑  收藏  举报