diff --git a/go.mod b/go.mod index 3cce6fb..af8534c 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.19 require ( github.com/leprosus/golang-ttl-map v1.1.7 - github.com/maxlerebourg/simpleredis v1.0.7 + github.com/maxlerebourg/simpleredis v1.0.9 ) diff --git a/go.sum b/go.sum index 23c6f4e..05f8381 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ github.com/leprosus/golang-ttl-map v1.1.7 h1:cF4AAFDDnJTFSV+/42sKLhmMluvLdRlCGS2UaifH6UM= github.com/leprosus/golang-ttl-map v1.1.7/go.mod h1:4QWHJPeVBbrkhOhXdhCv9IEiyj/YzkO04/iexy4vSe0= -github.com/maxlerebourg/simpleredis v1.0.7 h1:d53p3GOIgQtxxWuqsWMGTJ0dZjP8UhiDX8L1q2QZ/vY= -github.com/maxlerebourg/simpleredis v1.0.7/go.mod h1:/DH8zOK6kDskSqoX/m5CJJdNGfkIQZd/ERBJgytDDSk= +github.com/maxlerebourg/simpleredis v1.0.9 h1:aj1hKaYPeOVE4Ksu3TV/zsreUDDWOpKXBAvoFysiqII= +github.com/maxlerebourg/simpleredis v1.0.9/go.mod h1:/DH8zOK6kDskSqoX/m5CJJdNGfkIQZd/ERBJgytDDSk= diff --git a/vendor/github.com/maxlerebourg/simpleredis/simpleredis.go b/vendor/github.com/maxlerebourg/simpleredis/simpleredis.go index dc36f26..0320ed6 100644 --- a/vendor/github.com/maxlerebourg/simpleredis/simpleredis.go +++ b/vendor/github.com/maxlerebourg/simpleredis/simpleredis.go @@ -18,6 +18,7 @@ const ( RedisMiss = "redis:miss" RedisTimeout = "redis:timeout" RedisNoAuth = "redis:noauth" + RedisIssue = "redis:issue?" ) // A redisCmd is used to communicate with redis at low level using commands. @@ -70,12 +71,11 @@ func (sr *SimpleRedis) waitRedis(reader *textproto.Reader, channel chan redisCmd } } -func (sr *SimpleRedis) askRedis(cmd redisCmd, channel chan redisCmd) { +func (sr *SimpleRedis) askRedis(cmd redisCmd, channel chan redisCmd) redisCmd { dialer := net.Dialer{Timeout: 2 * time.Second} conn, err := dialer.Dial("tcp", sr.host) if err != nil { - channel <- redisCmd{Error: fmt.Errorf(RedisUnreachable)} - return + return redisCmd{Error: fmt.Errorf(RedisUnreachable)} } defer func() { if err := conn.Close(); err != nil { @@ -111,24 +111,22 @@ func (sr *SimpleRedis) askRedis(cmd redisCmd, channel chan redisCmd) { for { select { case <-time.After(time.Second * 1): - channel <- redisCmd{Error: fmt.Errorf(RedisTimeout)} - return + return redisCmd{Error: fmt.Errorf(RedisTimeout)} default: read, _ := reader.ReadLineBytes() str := string(read) if strings.Contains(str, "-NOAUTH") { - channel <- redisCmd{Error: fmt.Errorf(RedisNoAuth)} - return + return redisCmd{Error: fmt.Errorf(RedisNoAuth)} } else if str != "$1" { - channel <- redisCmd{Error: fmt.Errorf(RedisMiss)} - return + return redisCmd{Error: fmt.Errorf(RedisMiss)} } read, _ = reader.ReadLineBytes() - channel <- redisCmd{Data: read} - return + return redisCmd{Data: read} + } } } + return redisCmd{Error: fmt.Errorf(RedisIssue)} } // Init sets the redisHost used to connect to redis. @@ -145,8 +143,7 @@ func (sr *SimpleRedis) Get(name string) ([]byte, error) { Name: name, } channel := make(chan redisCmd) - go sr.askRedis(cmd, channel) - resp := <-channel + resp := sr.askRedis(cmd, channel) if resp.Error != nil { return nil, resp.Error } @@ -161,7 +158,7 @@ func (sr *SimpleRedis) Set(name string, data []byte, duration int64) error { Data: data, Duration: duration, } - go sr.askRedis(cmd, nil) + sr.askRedis(cmd, nil) return nil } @@ -171,6 +168,6 @@ func (sr *SimpleRedis) Del(name string) error { Command: "DEL", Name: name, } - go sr.askRedis(cmd, nil) + sr.askRedis(cmd, nil) return nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index 36b8c06..b237031 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,6 +1,6 @@ # github.com/leprosus/golang-ttl-map v1.1.7 ## explicit; go 1.15 github.com/leprosus/golang-ttl-map -# github.com/maxlerebourg/simpleredis v1.0.7 +# github.com/maxlerebourg/simpleredis v1.0.9 ## explicit; go 1.19 github.com/maxlerebourg/simpleredis