Skip to content

Commit 2baad40

Browse files
committed
Merge branch 'master' of github.com:go-redis/redis
2 parents 85f34e0 + 370773b commit 2baad40

File tree

8 files changed

+50
-14
lines changed

8 files changed

+50
-14
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
go-version: [1.16.x, 1.17.x]
16+
go-version: [1.17.x, 1.18.x]
1717

1818
services:
1919
redis:

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ require (
66
github.com/cespare/xxhash/v2 v2.1.2
77
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f
88
github.com/onsi/ginkgo v1.16.5
9-
github.com/onsi/gomega v1.18.1
9+
github.com/onsi/gomega v1.19.0
1010
)
1111

1212
require (
1313
github.com/fsnotify/fsnotify v1.4.9 // indirect
1414
github.com/nxadm/tail v1.4.8 // indirect
15-
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect
15+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
1616
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
17-
golang.org/x/text v0.3.6 // indirect
17+
golang.org/x/text v0.3.7 // indirect
1818
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
1919
gopkg.in/yaml.v2 v2.4.0 // indirect
2020
)

go.sum

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108
3636
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
3737
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
3838
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
39-
github.com/onsi/ginkgo/v2 v2.0.0 h1:CcuG/HvWNkkaqCUpJifQY8z7qEMBJya6aLPx6ftGyjQ=
40-
github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
39+
github.com/onsi/ginkgo/v2 v2.1.3 h1:e/3Cwtogj0HA+25nMP1jCMDIf8RtRYbGwGGuBIFztkc=
40+
github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
4141
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
4242
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
4343
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
44-
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
45-
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
44+
github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
45+
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
4646
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4747
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
4848
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
@@ -56,8 +56,9 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
5656
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
5757
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
5858
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
59-
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
6059
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
60+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
61+
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
6162
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6263
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
6364
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -73,13 +74,16 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
7374
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7475
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7576
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
77+
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7678
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
7779
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7880
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
81+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
7982
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
8083
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
81-
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
8284
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
85+
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
86+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
8387
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
8488
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
8589
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=

internal/pool/conn.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,21 @@ func (cn *Conn) RemoteAddr() net.Addr {
6464
}
6565

6666
func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error) error {
67-
if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
68-
return err
67+
if timeout != 0 {
68+
if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil {
69+
return err
70+
}
6971
}
7072
return fn(cn.rd)
7173
}
7274

7375
func (cn *Conn) WithWriter(
7476
ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error,
7577
) error {
76-
if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
77-
return err
78+
if timeout != 0 {
79+
if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil {
80+
return err
81+
}
7882
}
7983

8084
if cn.bw.Buffered() > 0 {

internal/proto/scan.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package proto
33
import (
44
"encoding"
55
"fmt"
6+
"net"
67
"reflect"
78
"time"
89

@@ -115,6 +116,9 @@ func Scan(b []byte, v interface{}) error {
115116
return nil
116117
case encoding.BinaryUnmarshaler:
117118
return v.UnmarshalBinary(b)
119+
case *net.IP:
120+
*v = b
121+
return nil
118122
default:
119123
return fmt.Errorf(
120124
"redis: can't unmarshal %T (consider implementing BinaryUnmarshaler)", v)

internal/proto/writer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding"
55
"fmt"
66
"io"
7+
"net"
78
"strconv"
89
"time"
910

@@ -106,6 +107,8 @@ func (w *Writer) WriteArg(v interface{}) error {
106107
return err
107108
}
108109
return w.bytes(b)
110+
case net.IP:
111+
return w.bytes(v)
109112
default:
110113
return fmt.Errorf(
111114
"redis: can't marshal %T (implement encoding.BinaryMarshaler)", v)

internal/proto/writer_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package proto_test
33
import (
44
"bytes"
55
"encoding"
6+
"fmt"
7+
"net"
68
"testing"
79
"time"
810

@@ -64,6 +66,13 @@ var _ = Describe("WriteBuffer", func() {
6466

6567
Expect(buf.Len()).To(Equal(15))
6668
})
69+
70+
It("should append net.IP", func() {
71+
ip := net.ParseIP("192.168.1.1")
72+
err := wr.WriteArgs([]interface{}{ip})
73+
Expect(err).NotTo(HaveOccurred())
74+
Expect(buf.String()).To(Equal(fmt.Sprintf("*1\r\n$16\r\n%s\r\n", bytes.NewBuffer(ip))))
75+
})
6776
})
6877

6978
type discard struct{}

redis_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,18 @@ var _ = Describe("Client", func() {
316316
err := client.Conn(ctx).Get(ctx, "this-key-does-not-exist").Err()
317317
Expect(err).To(Equal(redis.Nil))
318318
})
319+
320+
It("should set and scan net.IP", func() {
321+
ip := net.ParseIP("192.168.1.1")
322+
err := client.Set(ctx, "ip", ip, 0).Err()
323+
Expect(err).NotTo(HaveOccurred())
324+
325+
var ip2 net.IP
326+
err = client.Get(ctx, "ip").Scan(&ip2)
327+
Expect(err).NotTo(HaveOccurred())
328+
329+
Expect(ip2).To(Equal(ip))
330+
})
319331
})
320332

321333
var _ = Describe("Client timeout", func() {

0 commit comments

Comments
 (0)