package main
import (
"fmt"
"sync"
"github.com/garyburd/redigo/redis"
)
func func_pool() {
var sw sync.WaitGroup
var pool = &redis.Pool{
MaxActive: 2000,
IdleTimeout: 20,
MaxIdle: 10,
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", "127.0.0.1:6379")
},
}
for i := 0; i < 10; i++ {
sw.Add(1)
go func() {
for j := 0; j < 100; j++ {
con := pool.Get()
value := fmt.Sprintf("Name%d%d", j, i)
fmt.Println(value)
reply, err := con.Do("SET", value, value, "EX", "100")
if err != nil {
fmt.Printf("set error %v \n", err)
return
}
fmt.Println(reply)
}
defer sw.Done()
}()
}
sw.Wait()
}
func main() {
func_pool()
}