Skip to content

Commit cff6b9b

Browse files
authored
Merge branch 'master' into ndyakov/token-based-auth
2 parents 544bdb2 + 683f644 commit cff6b9b

File tree

18 files changed

+147
-32
lines changed

18 files changed

+147
-32
lines changed

.github/actions/run-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runs:
2525
2626
# Mapping of redis version to redis testing containers
2727
declare -A redis_version_mapping=(
28-
["8.0-RC1"]="8.0-RC1-pre"
28+
["8.0-RC2"]="8.0-RC2-pre"
2929
["7.4.2"]="rs-7.4.0-v2"
3030
["7.2.7"]="rs-7.2.0-v14"
3131
)

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
redis-version:
21-
- "8.0-RC1" # 8.0 RC1
21+
- "8.0-RC2" # 8.0 RC2
2222
- "7.4.2" # should use redis stack 7.4
2323
go-version:
2424
- "1.23.x"
@@ -43,7 +43,7 @@ jobs:
4343
4444
# Mapping of redis version to redis testing containers
4545
declare -A redis_version_mapping=(
46-
["8.0-RC1"]="8.0-RC1-pre"
46+
["8.0-RC2"]="8.0-RC2-pre"
4747
["7.4.2"]="rs-7.4.0-v2"
4848
)
4949
if [[ -v redis_version_mapping[$REDIS_VERSION] ]]; then
@@ -72,7 +72,7 @@ jobs:
7272
fail-fast: false
7373
matrix:
7474
redis-version:
75-
- "8.0-RC1" # 8.0 RC1
75+
- "8.0-RC2" # 8.0 RC2
7676
- "7.4.2" # should use redis stack 7.4
7777
- "7.2.7" # should redis stack 7.2
7878
go-version:

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v4
2323
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v6.5.2
24+
uses: golangci/golangci-lint-action@v7.0.0
2525
with:
26-
verify: false # disable verifying the configuration since golangci is currently introducing breaking changes in the configuration
26+
verify: true
2727

.golangci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
version: "2"
12
run:
23
timeout: 5m
34
tests: false
5+
linters:
6+
settings:
7+
staticcheck:
8+
checks:
9+
- all
10+
# Incorrect or missing package comment.
11+
# https://staticcheck.dev/docs/checks/#ST1000
12+
- -ST1000
13+
# Omit embedded fields from selector expression.
14+
# https://staticcheck.dev/docs/checks/#QF1008
15+
- -QF1008
16+
- -ST1003
17+
exclusions:
18+
generated: lax
19+
presets:
20+
- comments
21+
- common-false-positives
22+
- legacy
23+
- std-error-handling
24+
paths:
25+
- third_party$
26+
- builtin$
27+
- examples$
28+
formatters:
29+
exclusions:
30+
generated: lax
31+
paths:
32+
- third_party$
33+
- builtin$
34+
- examples$

command.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,8 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) {
14121412

14131413
cmd.val = make(map[string][]interface{})
14141414

1415-
if readType == proto.RespMap {
1415+
switch readType {
1416+
case proto.RespMap:
14161417
n, err := rd.ReadMapLen()
14171418
if err != nil {
14181419
return err
@@ -1435,7 +1436,7 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) {
14351436
cmd.val[k][j] = value
14361437
}
14371438
}
1438-
} else if readType == proto.RespArray {
1439+
case proto.RespArray:
14391440
// RESP2 response
14401441
n, err := rd.ReadArrayLen()
14411442
if err != nil {

commands.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ func isEmptyValue(v reflect.Value) bool {
155155
return v.Float() == 0
156156
case reflect.Interface, reflect.Pointer:
157157
return v.IsNil()
158+
case reflect.Struct:
159+
if v.Type() == reflect.TypeOf(time.Time{}) {
160+
return v.IsZero()
161+
}
162+
// Only supports the struct time.Time,
163+
// subsequent iterations will follow the func Scan support decoder.
158164
}
159165
return false
160166
}

commands_test.go

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,63 @@ var _ = Describe("Commands", func() {
25782578
"val2",
25792579
"val",
25802580
}))
2581+
2582+
type setOmitEmpty struct {
2583+
Set1 string `redis:"set1"`
2584+
Set2 int `redis:"set2,omitempty"`
2585+
Set3 time.Duration `redis:"set3,omitempty"`
2586+
Set4 string `redis:"set4,omitempty"`
2587+
Set5 time.Time `redis:"set5,omitempty"`
2588+
Set6 *numberStruct `redis:"set6,omitempty"`
2589+
Set7 numberStruct `redis:"set7,omitempty"`
2590+
}
2591+
2592+
hSet = client.HSet(ctx, "hash3", &setOmitEmpty{
2593+
Set1: "val",
2594+
})
2595+
Expect(hSet.Err()).NotTo(HaveOccurred())
2596+
// both set1 and set7 are set
2597+
// custom struct is not omitted
2598+
Expect(hSet.Val()).To(Equal(int64(2)))
2599+
2600+
hGetAll := client.HGetAll(ctx, "hash3")
2601+
Expect(hGetAll.Err()).NotTo(HaveOccurred())
2602+
Expect(hGetAll.Val()).To(Equal(map[string]string{
2603+
"set1": "val",
2604+
"set7": `{"Number":0}`,
2605+
}))
2606+
var hash3 setOmitEmpty
2607+
Expect(hGetAll.Scan(&hash3)).NotTo(HaveOccurred())
2608+
Expect(hash3.Set1).To(Equal("val"))
2609+
Expect(hash3.Set2).To(Equal(0))
2610+
Expect(hash3.Set3).To(Equal(time.Duration(0)))
2611+
Expect(hash3.Set4).To(Equal(""))
2612+
Expect(hash3.Set5).To(Equal(time.Time{}))
2613+
Expect(hash3.Set6).To(BeNil())
2614+
Expect(hash3.Set7).To(Equal(numberStruct{}))
2615+
2616+
now := time.Now()
2617+
hSet = client.HSet(ctx, "hash4", setOmitEmpty{
2618+
Set1: "val",
2619+
Set5: now,
2620+
Set6: &numberStruct{
2621+
Number: 5,
2622+
},
2623+
Set7: numberStruct{
2624+
Number: 3,
2625+
},
2626+
})
2627+
Expect(hSet.Err()).NotTo(HaveOccurred())
2628+
Expect(hSet.Val()).To(Equal(int64(4)))
2629+
2630+
hGetAll = client.HGetAll(ctx, "hash4")
2631+
Expect(hGetAll.Err()).NotTo(HaveOccurred())
2632+
Expect(hGetAll.Val()).To(Equal(map[string]string{
2633+
"set1": "val",
2634+
"set5": now.Format(time.RFC3339Nano),
2635+
"set6": `{"Number":5}`,
2636+
"set7": `{"Number":3}`,
2637+
}))
25812638
})
25822639

25832640
It("should HSetNX", func() {
@@ -7619,12 +7676,16 @@ type numberStruct struct {
76197676
Number int
76207677
}
76217678

7622-
func (s *numberStruct) MarshalBinary() ([]byte, error) {
7623-
return json.Marshal(s)
7679+
func (n numberStruct) MarshalBinary() ([]byte, error) {
7680+
return json.Marshal(n)
7681+
}
7682+
7683+
func (n *numberStruct) UnmarshalBinary(b []byte) error {
7684+
return json.Unmarshal(b, n)
76247685
}
76257686

7626-
func (s *numberStruct) UnmarshalBinary(b []byte) error {
7627-
return json.Unmarshal(b, s)
7687+
func (n *numberStruct) ScanRedis(str string) error {
7688+
return json.Unmarshal([]byte(str), n)
76287689
}
76297690

76307691
func deref(viface interface{}) interface{} {

extra/rediscensus/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ require (
1919
)
2020

2121
retract (
22-
v9.5.3 // This version was accidentally released.
2322
v9.7.2 // This version was accidentally released.
23+
v9.5.3 // This version was accidentally released.
2424
)

extra/rediscmd/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ require (
1616
)
1717

1818
retract (
19-
v9.5.3 // This version was accidentally released.
2019
v9.7.2 // This version was accidentally released.
20+
v9.5.3 // This version was accidentally released.
2121
)

extra/redisotel/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ require (
2424
)
2525

2626
retract (
27-
v9.5.3 // This version was accidentally released.
2827
v9.7.2 // This version was accidentally released.
28+
v9.5.3 // This version was accidentally released.
2929
)

extra/redisprometheus/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ require (
2323
)
2424

2525
retract (
26-
v9.5.3 // This version was accidentally released.
2726
v9.7.2 // This version was accidentally released.
27+
v9.5.3 // This version was accidentally released.
2828
)

options.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ func (opt *Options) init() {
265265
opt.ConnMaxIdleTime = 30 * time.Minute
266266
}
267267

268-
if opt.MaxRetries == -1 {
268+
switch opt.MaxRetries {
269+
case -1:
269270
opt.MaxRetries = 0
270-
} else if opt.MaxRetries == 0 {
271+
case 0:
271272
opt.MaxRetries = 3
272273
}
273274
switch opt.MinRetryBackoff {

osscluster.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ type ClusterOptions struct {
113113
}
114114

115115
func (opt *ClusterOptions) init() {
116-
if opt.MaxRedirects == -1 {
116+
switch opt.MaxRedirects {
117+
case -1:
117118
opt.MaxRedirects = 0
118-
} else if opt.MaxRedirects == 0 {
119+
case 0:
119120
opt.MaxRedirects = 3
120121
}
121122

pubsub.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func (c *PubSub) init() {
4545
}
4646

4747
func (c *PubSub) String() string {
48+
c.mu.Lock()
49+
defer c.mu.Unlock()
50+
4851
channels := mapKeys(c.channels)
4952
channels = append(channels, mapKeys(c.patterns)...)
5053
channels = append(channels, mapKeys(c.schannels)...)

ring.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ func (opt *RingOptions) init() {
128128
opt.NewConsistentHash = newRendezvous
129129
}
130130

131-
if opt.MaxRetries == -1 {
131+
switch opt.MaxRetries {
132+
case -1:
132133
opt.MaxRetries = 0
133-
} else if opt.MaxRetries == 0 {
134+
case 0:
134135
opt.MaxRetries = 3
135136
}
136137
switch opt.MinRetryBackoff {

sentinel_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var _ = Describe("Sentinel resolution", func() {
4141
client := redis.NewFailoverClient(&redis.FailoverOptions{
4242
MasterName: sentinelName,
4343
SentinelAddrs: sentinelAddrs,
44-
MaxRetries: -1,
44+
MaxRetries: -1,
4545
})
4646

4747
err := client.Ping(shortCtx).Err()

timeseries_commands_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,21 @@ var _ = Describe("RedisTimeseries commands", Label("timeseries"), func() {
269269
if client.Options().Protocol == 2 {
270270
Expect(resultInfo["labels"].([]interface{})[0]).To(BeEquivalentTo([]interface{}{"Time", "Series"}))
271271
Expect(resultInfo["retentionTime"]).To(BeEquivalentTo(10))
272-
Expect(resultInfo["duplicatePolicy"]).To(BeEquivalentTo(redis.Nil))
272+
if RedisVersion >= 8 {
273+
Expect(resultInfo["duplicatePolicy"]).To(BeEquivalentTo("block"))
274+
} else {
275+
// Older versions of Redis had a bug where the duplicate policy was not set correctly
276+
Expect(resultInfo["duplicatePolicy"]).To(BeEquivalentTo(redis.Nil))
277+
}
273278
} else {
274279
Expect(resultInfo["labels"].(map[interface{}]interface{})["Time"]).To(BeEquivalentTo("Series"))
275280
Expect(resultInfo["retentionTime"]).To(BeEquivalentTo(10))
276-
Expect(resultInfo["duplicatePolicy"]).To(BeEquivalentTo(redis.Nil))
281+
if RedisVersion >= 8 {
282+
Expect(resultInfo["duplicatePolicy"]).To(BeEquivalentTo("block"))
283+
} else {
284+
// Older versions of Redis had a bug where the duplicate policy was not set correctly
285+
Expect(resultInfo["duplicatePolicy"]).To(BeEquivalentTo(redis.Nil))
286+
}
277287
}
278288
opt = &redis.TSAlterOptions{DuplicatePolicy: "min"}
279289
resultAlter, err = client.TSAlter(ctx, "1", opt).Result()

universal.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,13 @@ var (
259259
// NewUniversalClient returns a new multi client. The type of the returned client depends
260260
// on the following conditions:
261261
//
262-
// 1. If the MasterName option is specified with RouteByLatency, RouteRandomly or IsClusterMode,
263-
// a FailoverClusterClient is returned.
264-
// 2. If the MasterName option is specified without RouteByLatency, RouteRandomly or IsClusterMode,
265-
// a sentinel-backed FailoverClient is returned.
266-
// 3. If the number of Addrs is two or more, or IsClusterMode option is specified,
267-
// a ClusterClient is returned.
268-
// 4. Otherwise, a single-node Client is returned.
262+
// 1. If the MasterName option is specified with RouteByLatency, RouteRandomly or IsClusterMode,
263+
// a FailoverClusterClient is returned.
264+
// 2. If the MasterName option is specified without RouteByLatency, RouteRandomly or IsClusterMode,
265+
// a sentinel-backed FailoverClient is returned.
266+
// 3. If the number of Addrs is two or more, or IsClusterMode option is specified,
267+
// a ClusterClient is returned.
268+
// 4. Otherwise, a single-node Client is returned.
269269
func NewUniversalClient(opts *UniversalOptions) UniversalClient {
270270
switch {
271271
case opts.MasterName != "" && (opts.RouteByLatency || opts.RouteRandomly || opts.IsClusterMode):

0 commit comments

Comments
 (0)