Skip to content

Commit dd8d920

Browse files
authored
Merge branch 'master' into do_cmd_for_simple_conn
2 parents b537f7c + 1505939 commit dd8d920

File tree

27 files changed

+516
-61
lines changed

27 files changed

+516
-61
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ jobs:
2121
steps:
2222
- uses: actions/checkout@v4
2323
- name: golangci-lint
24-
uses: golangci/[email protected].1
24+
uses: golangci/[email protected].2

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,18 @@ By default, go-redis automatically sends the client library name and version dur
178178

179179
#### Disabling Identity Verification
180180

181-
When connection identity verification is not required or needs to be explicitly disabled, a `DisableIndentity` configuration option exists. In V10 of this library, `DisableIndentity` will become `DisableIdentity` in order to fix the associated typo.
181+
When connection identity verification is not required or needs to be explicitly disabled, a `DisableIdentity` configuration option exists.
182+
Initially there was a typo and the option was named `DisableIndentity` instead of `DisableIdentity`. The misspelled option is marked as Deprecated and will be removed in V10 of this library.
183+
Although both options will work at the moment, the correct option is `DisableIdentity`. The deprecated option will be removed in V10 of this library, so please use the correct option name to avoid any issues.
182184

183-
To disable verification, set the `DisableIndentity` option to `true` in the Redis client options:
185+
To disable verification, set the `DisableIdentity` option to `true` in the Redis client options:
184186

185187
```go
186188
rdb := redis.NewClient(&redis.Options{
187189
Addr: "localhost:6379",
188190
Password: "",
189191
DB: 0,
190-
DisableIndentity: true, // Disable set-info on connect
192+
DisableIdentity: true, // Disable set-info on connect
191193
})
192194
```
193195

bench_decode_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewClientStub(resp []byte) *ClientStub {
3030
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
3131
return stub.stubConn(initHello), nil
3232
},
33-
DisableIndentity: true,
33+
DisableIdentity: true,
3434
})
3535
return stub
3636
}
@@ -46,7 +46,7 @@ func NewClusterClientStub(resp []byte) *ClientStub {
4646
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
4747
return stub.stubConn(initHello), nil
4848
},
49-
DisableIndentity: true,
49+
DisableIdentity: true,
5050

5151
ClusterSlots: func(_ context.Context) ([]ClusterSlot, error) {
5252
return []ClusterSlot{

commands_test.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,6 +2817,148 @@ var _ = Describe("Commands", func() {
28172817
Expect(err).NotTo(HaveOccurred())
28182818
Expect(res[0]).To(BeNumerically("~", 10*time.Second.Milliseconds(), 1))
28192819
})
2820+
2821+
It("should HGETDEL", Label("hash", "HGETDEL"), func() {
2822+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2823+
2824+
err := client.HSet(ctx, "myhash", "f1", "val1", "f2", "val2", "f3", "val3").Err()
2825+
Expect(err).NotTo(HaveOccurred())
2826+
2827+
// Execute HGETDEL on fields f1 and f2.
2828+
res, err := client.HGetDel(ctx, "myhash", "f1", "f2").Result()
2829+
Expect(err).NotTo(HaveOccurred())
2830+
// Expect the returned values for f1 and f2.
2831+
Expect(res).To(Equal([]string{"val1", "val2"}))
2832+
2833+
// Verify that f1 and f2 have been deleted, while f3 remains.
2834+
remaining, err := client.HMGet(ctx, "myhash", "f1", "f2", "f3").Result()
2835+
Expect(err).NotTo(HaveOccurred())
2836+
Expect(remaining[0]).To(BeNil())
2837+
Expect(remaining[1]).To(BeNil())
2838+
Expect(remaining[2]).To(Equal("val3"))
2839+
})
2840+
2841+
It("should return nil responses for HGETDEL on non-existent key", Label("hash", "HGETDEL"), func() {
2842+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2843+
// HGETDEL on a key that does not exist.
2844+
res, err := client.HGetDel(ctx, "nonexistent", "f1", "f2").Result()
2845+
Expect(err).To(BeNil())
2846+
Expect(res).To(Equal([]string{"", ""}))
2847+
})
2848+
2849+
// -----------------------------
2850+
// HGETEX with various TTL options
2851+
// -----------------------------
2852+
It("should HGETEX with EX option", Label("hash", "HGETEX"), func() {
2853+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2854+
2855+
err := client.HSet(ctx, "myhash", "f1", "val1", "f2", "val2").Err()
2856+
Expect(err).NotTo(HaveOccurred())
2857+
2858+
// Call HGETEX with EX option and 60 seconds TTL.
2859+
opt := redis.HGetEXOptions{
2860+
ExpirationType: redis.HGetEXExpirationEX,
2861+
ExpirationVal: 60,
2862+
}
2863+
res, err := client.HGetEXWithArgs(ctx, "myhash", &opt, "f1", "f2").Result()
2864+
Expect(err).NotTo(HaveOccurred())
2865+
Expect(res).To(Equal([]string{"val1", "val2"}))
2866+
})
2867+
2868+
It("should HGETEX with PERSIST option", Label("hash", "HGETEX"), func() {
2869+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2870+
2871+
err := client.HSet(ctx, "myhash", "f1", "val1", "f2", "val2").Err()
2872+
Expect(err).NotTo(HaveOccurred())
2873+
2874+
// Call HGETEX with PERSIST (no TTL value needed).
2875+
opt := redis.HGetEXOptions{ExpirationType: redis.HGetEXExpirationPERSIST}
2876+
res, err := client.HGetEXWithArgs(ctx, "myhash", &opt, "f1", "f2").Result()
2877+
Expect(err).NotTo(HaveOccurred())
2878+
Expect(res).To(Equal([]string{"val1", "val2"}))
2879+
})
2880+
2881+
It("should HGETEX with EXAT option", Label("hash", "HGETEX"), func() {
2882+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2883+
2884+
err := client.HSet(ctx, "myhash", "f1", "val1", "f2", "val2").Err()
2885+
Expect(err).NotTo(HaveOccurred())
2886+
2887+
// Set expiration at a specific Unix timestamp (60 seconds from now).
2888+
expireAt := time.Now().Add(60 * time.Second).Unix()
2889+
opt := redis.HGetEXOptions{
2890+
ExpirationType: redis.HGetEXExpirationEXAT,
2891+
ExpirationVal: expireAt,
2892+
}
2893+
res, err := client.HGetEXWithArgs(ctx, "myhash", &opt, "f1", "f2").Result()
2894+
Expect(err).NotTo(HaveOccurred())
2895+
Expect(res).To(Equal([]string{"val1", "val2"}))
2896+
})
2897+
2898+
// -----------------------------
2899+
// HSETEX with FNX/FXX options
2900+
// -----------------------------
2901+
It("should HSETEX with FNX condition", Label("hash", "HSETEX"), func() {
2902+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2903+
2904+
opt := redis.HSetEXOptions{
2905+
Condition: redis.HSetEXFNX,
2906+
ExpirationType: redis.HSetEXExpirationEX,
2907+
ExpirationVal: 60,
2908+
}
2909+
res, err := client.HSetEXWithArgs(ctx, "myhash", &opt, "f1", "val1").Result()
2910+
Expect(err).NotTo(HaveOccurred())
2911+
Expect(res).To(Equal(int64(1)))
2912+
2913+
opt = redis.HSetEXOptions{
2914+
Condition: redis.HSetEXFNX,
2915+
ExpirationType: redis.HSetEXExpirationEX,
2916+
ExpirationVal: 60,
2917+
}
2918+
res, err = client.HSetEXWithArgs(ctx, "myhash", &opt, "f1", "val2").Result()
2919+
Expect(err).NotTo(HaveOccurred())
2920+
Expect(res).To(Equal(int64(0)))
2921+
})
2922+
2923+
It("should HSETEX with FXX condition", Label("hash", "HSETEX"), func() {
2924+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2925+
2926+
err := client.HSet(ctx, "myhash", "f2", "val1").Err()
2927+
Expect(err).NotTo(HaveOccurred())
2928+
2929+
opt := redis.HSetEXOptions{
2930+
Condition: redis.HSetEXFXX,
2931+
ExpirationType: redis.HSetEXExpirationEX,
2932+
ExpirationVal: 60,
2933+
}
2934+
res, err := client.HSetEXWithArgs(ctx, "myhash", &opt, "f2", "val2").Result()
2935+
Expect(err).NotTo(HaveOccurred())
2936+
Expect(res).To(Equal(int64(1)))
2937+
opt = redis.HSetEXOptions{
2938+
Condition: redis.HSetEXFXX,
2939+
ExpirationType: redis.HSetEXExpirationEX,
2940+
ExpirationVal: 60,
2941+
}
2942+
res, err = client.HSetEXWithArgs(ctx, "myhash", &opt, "f3", "val3").Result()
2943+
Expect(err).NotTo(HaveOccurred())
2944+
Expect(res).To(Equal(int64(0)))
2945+
})
2946+
2947+
It("should HSETEX with multiple field operations", Label("hash", "HSETEX"), func() {
2948+
SkipBeforeRedisVersion(7.9, "requires Redis 8.x")
2949+
2950+
opt := redis.HSetEXOptions{
2951+
ExpirationType: redis.HSetEXExpirationEX,
2952+
ExpirationVal: 60,
2953+
}
2954+
res, err := client.HSetEXWithArgs(ctx, "myhash", &opt, "f1", "val1", "f2", "val2").Result()
2955+
Expect(err).NotTo(HaveOccurred())
2956+
Expect(res).To(Equal(int64(1)))
2957+
2958+
values, err := client.HMGet(ctx, "myhash", "f1", "f2").Result()
2959+
Expect(err).NotTo(HaveOccurred())
2960+
Expect(values).To(Equal([]interface{}{"val1", "val2"}))
2961+
})
28202962
})
28212963

28222964
Describe("hyperloglog", func() {

doctests/cmds_set_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// EXAMPLE: cmds_set
2+
// HIDE_START
3+
package example_commands_test
4+
5+
import (
6+
"context"
7+
"fmt"
8+
9+
"github.com/redis/go-redis/v9"
10+
)
11+
12+
// HIDE_END
13+
14+
func ExampleClient_sadd_cmd() {
15+
ctx := context.Background()
16+
17+
rdb := redis.NewClient(&redis.Options{
18+
Addr: "localhost:6379",
19+
Password: "", // no password docs
20+
DB: 0, // use default DB
21+
})
22+
23+
// REMOVE_START
24+
rdb.Del(ctx, "myset")
25+
// REMOVE_END
26+
27+
// STEP_START sadd
28+
sAddResult1, err := rdb.SAdd(ctx, "myset", "Hello").Result()
29+
30+
if err != nil {
31+
panic(err)
32+
}
33+
34+
fmt.Println(sAddResult1) // >>> 1
35+
36+
sAddResult2, err := rdb.SAdd(ctx, "myset", "World").Result()
37+
38+
if err != nil {
39+
panic(err)
40+
}
41+
42+
fmt.Println(sAddResult2) // >>> 1
43+
44+
sAddResult3, err := rdb.SAdd(ctx, "myset", "World").Result()
45+
46+
if err != nil {
47+
panic(err)
48+
}
49+
50+
fmt.Println(sAddResult3) // >>> 0
51+
52+
sMembersResult, err := rdb.SMembers(ctx, "myset").Result()
53+
54+
if err != nil {
55+
panic(err)
56+
}
57+
58+
fmt.Println(sMembersResult) // >>> [Hello World]
59+
// STEP_END
60+
61+
// Output:
62+
// 1
63+
// 1
64+
// 0
65+
// [Hello World]
66+
}
67+
68+
func ExampleClient_smembers_cmd() {
69+
ctx := context.Background()
70+
71+
rdb := redis.NewClient(&redis.Options{
72+
Addr: "localhost:6379",
73+
Password: "", // no password docs
74+
DB: 0, // use default DB
75+
})
76+
77+
// REMOVE_START
78+
rdb.Del(ctx, "myset")
79+
// REMOVE_END
80+
81+
// STEP_START smembers
82+
sAddResult, err := rdb.SAdd(ctx, "myset", "Hello", "World").Result()
83+
84+
if err != nil {
85+
panic(err)
86+
}
87+
88+
fmt.Println(sAddResult) // >>> 2
89+
90+
sMembersResult, err := rdb.SMembers(ctx, "myset").Result()
91+
92+
if err != nil {
93+
panic(err)
94+
}
95+
96+
fmt.Println(sMembersResult) // >>> [Hello World]
97+
// STEP_END
98+
99+
// Output:
100+
// 2
101+
// [Hello World]
102+
}

example/del-keys-without-ttl/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
replace github.com/redis/go-redis/v9 => ../..
66

77
require (
8-
github.com/redis/go-redis/v9 v9.7.1
8+
github.com/redis/go-redis/v9 v9.7.3
99
go.uber.org/zap v1.24.0
1010
)
1111

example/hll/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
replace github.com/redis/go-redis/v9 => ../..
66

7-
require github.com/redis/go-redis/v9 v9.7.1
7+
require github.com/redis/go-redis/v9 v9.7.3
88

99
require (
1010
github.com/cespare/xxhash/v2 v2.3.0 // indirect

example/hset-struct/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
22
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
3-
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
4-
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
53
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
64
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
75
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

example/lua-scripting/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
replace github.com/redis/go-redis/v9 => ../..
66

7-
require github.com/redis/go-redis/v9 v9.7.1
7+
require github.com/redis/go-redis/v9 v9.7.3
88

99
require (
1010
github.com/cespare/xxhash/v2 v2.3.0 // indirect

example/otel/go.mod

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module github.com/redis/go-redis/example/otel
22

3-
go 1.19
3+
go 1.23.0
4+
5+
toolchain go1.24.1
46

57
replace github.com/redis/go-redis/v9 => ../..
68

@@ -9,8 +11,8 @@ replace github.com/redis/go-redis/extra/redisotel/v9 => ../../extra/redisotel
911
replace github.com/redis/go-redis/extra/rediscmd/v9 => ../../extra/rediscmd
1012

1113
require (
12-
github.com/redis/go-redis/extra/redisotel/v9 v9.7.1
13-
github.com/redis/go-redis/v9 v9.7.1
14+
github.com/redis/go-redis/extra/redisotel/v9 v9.7.3
15+
github.com/redis/go-redis/v9 v9.7.3
1416
github.com/uptrace/uptrace-go v1.21.0
1517
go.opentelemetry.io/otel v1.22.0
1618
)
@@ -23,7 +25,7 @@ require (
2325
github.com/go-logr/stdr v1.2.2 // indirect
2426
github.com/golang/protobuf v1.5.3 // indirect
2527
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
26-
github.com/redis/go-redis/extra/rediscmd/v9 v9.7.1 // indirect
28+
github.com/redis/go-redis/extra/rediscmd/v9 v9.7.3 // indirect
2729
go.opentelemetry.io/contrib/instrumentation/runtime v0.46.1 // indirect
2830
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0 // indirect
2931
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
@@ -34,9 +36,9 @@ require (
3436
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect
3537
go.opentelemetry.io/otel/trace v1.22.0 // indirect
3638
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
37-
golang.org/x/net v0.33.0 // indirect
38-
golang.org/x/sys v0.28.0 // indirect
39-
golang.org/x/text v0.21.0 // indirect
39+
golang.org/x/net v0.36.0 // indirect
40+
golang.org/x/sys v0.30.0 // indirect
41+
golang.org/x/text v0.22.0 // indirect
4042
google.golang.org/genproto v0.0.0-20240108191215-35c7eff3a6b1 // indirect
4143
google.golang.org/genproto/googleapis/api v0.0.0-20240108191215-35c7eff3a6b1 // indirect
4244
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect

0 commit comments

Comments
 (0)