下载
go get github.com/gomodule/redigo/redis
创建连接池
var Pool *redis.Pool
// GetPool
//
// @Description:
func GetPool(data configure.Configure) {
Pool = &redis.Pool{
MaxIdle: 8, //最大空闲连接数
MaxActive: 0, //数据库最大连接数,0表示最大,无限制
IdleTimeout: 100, //最大空闲时间
Dial: func() (redis.Conn, error) { //初始化连接代码
return redis.Dial("tcp", "127.0.0.1:7811")
},
}
}
func main(){
Pool.Get().Do("LPUSH", "ttt" 0)
tt2, _ := redis.String(Pool.Get().Do("RPOP", “ttt”))
fmt.Println(tt2)
Pool.Get().Do("SET", "ttt",0)
Pool.Get().Do("GET", "ttt")
}