β

go redis 连接池

海运的博客 1004 阅读
package main
import (
  "github.com/garyburd/redigo/redis"
  "fmt"
)
var pool = newPool()
func newPool() *redis.Pool {
  return &redis.Pool{
    MaxIdle: 80,
    MaxActive: 12000, // max number of connections
    Dial: func() (redis.Conn, error) {
      c, err := redis.Dial("tcp", "localhost:6379")
      if err != nil {
        panic(err.Error())
      }
      return c, err
    },
  } 

}
func main() {
  c := pool.Get()
  defer c.Close()
  que, err := redis.String(c.Do("LPOP", "test"))
  fmt.Println(que)
  if err != nil {
    fmt.Println("队列空")
  }
}

http://stackoverflow.com/questions/24387350/re-using-redigo-connection-instead-of-recreating-it-every-time
http://blog.csdn.net/stevefang/article/details/40474827

作者:海运的博客
个人笔记
原文地址:go redis 连接池, 感谢原作者分享。

发表评论