Add sync => go-sync

This commit is contained in:
Asim Aslam
2019-05-31 00:43:23 +01:00
parent 4035ab5c7b
commit 95d134b57e
28 changed files with 2192 additions and 0 deletions

29
sync/lock/redis/pool.go Normal file
View File

@@ -0,0 +1,29 @@
package redis
import (
"sync"
"github.com/gomodule/redigo/redis"
)
type pool struct {
sync.Mutex
i int
addrs []string
}
func (p *pool) Get() redis.Conn {
for i := 0; i < 3; i++ {
p.Lock()
addr := p.addrs[p.i%len(p.addrs)]
p.i++
p.Unlock()
c, err := redis.Dial("tcp", addr)
if err != nil {
continue
}
return c
}
return nil
}