Go 操作redis 连接池,怎么初始化啊,不会,求大神!!!

luckRay · · 1232 次点击
https://github.com/eehsiao/go-models-redis/blob/master/redis.go 參考 ``` import ( "github.com/go-redis/redis" ) .... cfg = &redis.Options{ Addr: addr, Password: pw, DB: db, PoolSize : active, MinIdleConns : idle, } db = redis.NewClient(cfg) ```
#2
更多评论
https://github.com/Gourouting/singo/blob/master/cache/main.go 这个项目可以跑起来,里面有redis,你可以参考参考
#1
```go import ( "fmt" "github.com/garyburd/redigo/redis" "time" ) var ( redispool *redis.Pool ) func init() { redispool = &redis.Pool{ MaxIdle: 1, MaxActive: 0, IdleTimeout: time.Second * 20, Dial: func() (conn redis.Conn, err error) { c, err := redis.Dial("tcp", "127.0.0.1:6379") if err != nil { fmt.Println("get connection error,", err.Error()) return nil, err } return c, nil }, } } func main(){ con:=redispool.Get() defer con.Close() res,err := redis.String(con.Do("ping")) if err!=nil{ fmt.Println(err.Error()) return } fmt.Println(res) } ```
#3