Programming/Go
golang - redigo 사용시 ping
woonizzooni
2020. 8. 3. 03:42
커넥션 풀을 사용했고, 반환(close())된지 1초 초과한 연결을 재사용할 경우 ping을 보내도록 했다.
pool = &redis.Pool{
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", addr)
},
TestOnBorrow: func(c redis.Conn, t time.Time) error {
if time.Since(t) > time.Second { // 사용 후 반환된 연결을 재사용할 경우, 그 간격이 1초 초과일 경우 Ping으로 소켓 연결 상태 확인.
_, err := c.Do("PING")
return err
}
return nil
},
MaxIdle: 4,
MaxActive: 16,
IdleTimeout: 10 * time.Second,
Wait: true,
MaxConnLifetime: 0,
}
...