Skip to content

Commit

Permalink
configure dial timeouts consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd committed Oct 3, 2023
1 parent fcc618c commit 35ea856
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ go test ./... --tags single,sentinel -count 1 -race



### Redis Port

```
export REDIS_PORT=6380
```

```
docker run --rm --name redis-stack-redigo -p 6380:6379 -p 8002:8001 redis/redis-stack:latest
```



### Lua Debugging

```
Expand Down
36 changes: 23 additions & 13 deletions pkg/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ import (
"github.com/gomodule/redigo/redis"
)

func NewSinglePoolWithAddress(address string) *redis.Pool {
func NewSinglePoolWithAddress(add string) *redis.Pool {
var opt []redis.DialOption
{
opt = []redis.DialOption{
redis.DialConnectTimeout(time.Second),
redis.DialReadTimeout(time.Second),
redis.DialWriteTimeout(time.Second),
}
}

var p *redis.Pool
{
p = &redis.Pool{
MaxIdle: 100,
MaxActive: 100,
IdleTimeout: 5 * time.Minute,
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", address)
c, err := redis.Dial("tcp", add, opt...)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -64,20 +73,21 @@ func NewSinglePoolWithConnection(connection redis.Conn) *redis.Pool {
return p
}

func NewSentinelPoolWithAddress(address string) *redis.Pool {
timeout := 500 * time.Millisecond
func NewSentinelPoolWithAddress(add string) *redis.Pool {
var opt []redis.DialOption
{
opt = []redis.DialOption{
redis.DialConnectTimeout(time.Second),
redis.DialReadTimeout(time.Second),
redis.DialWriteTimeout(time.Second),
}
}

sntnl := &sentinel.Sentinel{
Addrs: []string{address},
Addrs: []string{add},
MasterName: "mymaster",
Dial: func(addr string) (redis.Conn, error) {
c, err := redis.Dial(
"tcp",
addr,
redis.DialConnectTimeout(timeout),
redis.DialReadTimeout(timeout),
redis.DialWriteTimeout(timeout),
)
Dial: func(a string) (redis.Conn, error) {
c, err := redis.Dial("tcp", a, opt...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 35ea856

Please sign in to comment.