MCPcopy Create free account
hub / github.com/LockGit/gochat / InitQueueRedisClient

Method InitQueueRedisClient

task/queue.go:18–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16var RedisClient *redis.Client
17
18func (task *Task) InitQueueRedisClient() (err error) {
19 redisOpt := tools.RedisOption{
20 Address: config.Conf.Common.CommonRedis.RedisAddress,
21 Password: config.Conf.Common.CommonRedis.RedisPassword,
22 Db: config.Conf.Common.CommonRedis.Db,
23 }
24 RedisClient = tools.GetRedisInstance(redisOpt)
25 if pong, err := RedisClient.Ping().Result(); err != nil {
26 logrus.Infof("RedisClient Ping Result pong: %s, err: %s", pong, err)
27 }
28 go func() {
29 for {
30 var result []string
31 //10s timeout
32 result, err = RedisClient.BRPop(time.Second*10, config.QueueName).Result()
33 if err != nil {
34 logrus.Infof("task queue block timeout,no msg err:%s", err.Error())
35 }
36 if len(result) >= 2 {
37 task.Push(result[1])
38 }
39 }
40 }()
41 return
42}

Callers 1

RunMethod · 0.95

Calls 2

PushMethod · 0.95
GetRedisInstanceFunction · 0.92

Tested by

no test coverage detected