Skip to content

Commit b73120d

Browse files
Merge branch 'master' into DOC-4228-json-tces
2 parents 1827deb + 233f97a commit b73120d

File tree

18 files changed

+2215
-9
lines changed

18 files changed

+2215
-9
lines changed

.github/wordlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
ACLs
2+
APIs
23
autoload
34
autoloader
45
autoloading
@@ -46,9 +47,11 @@ runtime
4647
SHA
4748
sharding
4849
SETNAME
50+
SpellCheck
4951
SSL
5052
struct
5153
stunnel
54+
SynDump
5255
TCP
5356
TLS
5457
uri

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ rdb := redis.NewClient(&redis.Options{
183183
})
184184
```
185185

186+
#### Unstable RESP3 Structures for RediSearch Commands
187+
When integrating Redis with application functionalities using RESP3, it's important to note that some response structures aren't final yet. This is especially true for more complex structures like search and query results. We recommend using RESP2 when using the search and query capabilities, but we plan to stabilize the RESP3-based API-s in the coming versions. You can find more guidance in the upcoming release notes.
188+
186189
## Contributing
187190

188191
Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library!

command.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Cmder interface {
4040

4141
readTimeout() *time.Duration
4242
readReply(rd *proto.Reader) error
43-
43+
readRawReply(rd *proto.Reader) error
4444
SetErr(error)
4545
Err() error
4646
}
@@ -122,11 +122,11 @@ func cmdString(cmd Cmder, val interface{}) string {
122122
//------------------------------------------------------------------------------
123123

124124
type baseCmd struct {
125-
ctx context.Context
126-
args []interface{}
127-
err error
128-
keyPos int8
129-
125+
ctx context.Context
126+
args []interface{}
127+
err error
128+
keyPos int8
129+
rawVal interface{}
130130
_readTimeout *time.Duration
131131
}
132132

@@ -197,6 +197,11 @@ func (cmd *baseCmd) setReadTimeout(d time.Duration) {
197197
cmd._readTimeout = &d
198198
}
199199

200+
func (cmd *baseCmd) readRawReply(rd *proto.Reader) (err error) {
201+
cmd.rawVal, err = rd.ReadReply()
202+
return err
203+
}
204+
200205
//------------------------------------------------------------------------------
201206

202207
type Cmd struct {

doctests/hash_tutorial_test.go

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
// EXAMPLE: hash_tutorial
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_set_get_all() {
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, "bike:1")
25+
// REMOVE_END
26+
27+
// STEP_START set_get_all
28+
hashFields := []string{
29+
"model", "Deimos",
30+
"brand", "Ergonom",
31+
"type", "Enduro bikes",
32+
"price", "4972",
33+
}
34+
35+
res1, err := rdb.HSet(ctx, "bike:1", hashFields).Result()
36+
37+
if err != nil {
38+
panic(err)
39+
}
40+
41+
fmt.Println(res1) // >>> 4
42+
43+
res2, err := rdb.HGet(ctx, "bike:1", "model").Result()
44+
45+
if err != nil {
46+
panic(err)
47+
}
48+
49+
fmt.Println(res2) // >>> Deimos
50+
51+
res3, err := rdb.HGet(ctx, "bike:1", "price").Result()
52+
53+
if err != nil {
54+
panic(err)
55+
}
56+
57+
fmt.Println(res3) // >>> 4972
58+
59+
cmdReturn := rdb.HGetAll(ctx, "bike:1")
60+
res4, err := cmdReturn.Result()
61+
62+
if err != nil {
63+
panic(err)
64+
}
65+
66+
fmt.Println(res4)
67+
// >>> map[brand:Ergonom model:Deimos price:4972 type:Enduro bikes]
68+
69+
type BikeInfo struct {
70+
Model string `redis:"model"`
71+
Brand string `redis:"brand"`
72+
Type string `redis:"type"`
73+
Price int `redis:"price"`
74+
}
75+
76+
var res4a BikeInfo
77+
78+
if err := cmdReturn.Scan(&res4a); err != nil {
79+
panic(err)
80+
}
81+
82+
fmt.Printf("Model: %v, Brand: %v, Type: %v, Price: $%v\n",
83+
res4a.Model, res4a.Brand, res4a.Type, res4a.Price)
84+
// >>> Model: Deimos, Brand: Ergonom, Type: Enduro bikes, Price: $4972
85+
// STEP_END
86+
87+
// Output:
88+
// 4
89+
// Deimos
90+
// 4972
91+
// map[brand:Ergonom model:Deimos price:4972 type:Enduro bikes]
92+
// Model: Deimos, Brand: Ergonom, Type: Enduro bikes, Price: $4972
93+
}
94+
95+
func ExampleClient_hmget() {
96+
ctx := context.Background()
97+
98+
rdb := redis.NewClient(&redis.Options{
99+
Addr: "localhost:6379",
100+
Password: "", // no password docs
101+
DB: 0, // use default DB
102+
})
103+
104+
// REMOVE_START
105+
rdb.Del(ctx, "bike:1")
106+
// REMOVE_END
107+
108+
hashFields := []string{
109+
"model", "Deimos",
110+
"brand", "Ergonom",
111+
"type", "Enduro bikes",
112+
"price", "4972",
113+
}
114+
115+
_, err := rdb.HSet(ctx, "bike:1", hashFields).Result()
116+
117+
if err != nil {
118+
panic(err)
119+
}
120+
121+
// STEP_START hmget
122+
cmdReturn := rdb.HMGet(ctx, "bike:1", "model", "price")
123+
res5, err := cmdReturn.Result()
124+
125+
if err != nil {
126+
panic(err)
127+
}
128+
129+
fmt.Println(res5) // >>> [Deimos 4972]
130+
131+
type BikeInfo struct {
132+
Model string `redis:"model"`
133+
Brand string `redis:"-"`
134+
Type string `redis:"-"`
135+
Price int `redis:"price"`
136+
}
137+
138+
var res5a BikeInfo
139+
140+
if err := cmdReturn.Scan(&res5a); err != nil {
141+
panic(err)
142+
}
143+
144+
fmt.Printf("Model: %v, Price: $%v\n", res5a.Model, res5a.Price)
145+
// >>> Model: Deimos, Price: $4972
146+
// STEP_END
147+
148+
// Output:
149+
// [Deimos 4972]
150+
// Model: Deimos, Price: $4972
151+
}
152+
153+
func ExampleClient_hincrby() {
154+
ctx := context.Background()
155+
156+
rdb := redis.NewClient(&redis.Options{
157+
Addr: "localhost:6379",
158+
Password: "", // no password docs
159+
DB: 0, // use default DB
160+
})
161+
162+
// REMOVE_START
163+
rdb.Del(ctx, "bike:1")
164+
// REMOVE_END
165+
166+
hashFields := []string{
167+
"model", "Deimos",
168+
"brand", "Ergonom",
169+
"type", "Enduro bikes",
170+
"price", "4972",
171+
}
172+
173+
_, err := rdb.HSet(ctx, "bike:1", hashFields).Result()
174+
175+
if err != nil {
176+
panic(err)
177+
}
178+
179+
// STEP_START hincrby
180+
res6, err := rdb.HIncrBy(ctx, "bike:1", "price", 100).Result()
181+
182+
if err != nil {
183+
panic(err)
184+
}
185+
186+
fmt.Println(res6) // >>> 5072
187+
188+
res7, err := rdb.HIncrBy(ctx, "bike:1", "price", -100).Result()
189+
190+
if err != nil {
191+
panic(err)
192+
}
193+
194+
fmt.Println(res7) // >>> 4972
195+
// STEP_END
196+
197+
// Output:
198+
// 5072
199+
// 4972
200+
}
201+
202+
func ExampleClient_incrby_get_mget() {
203+
ctx := context.Background()
204+
205+
rdb := redis.NewClient(&redis.Options{
206+
Addr: "localhost:6379",
207+
Password: "", // no password docs
208+
DB: 0, // use default DB
209+
})
210+
211+
// REMOVE_START
212+
rdb.Del(ctx, "bike:1:stats")
213+
// REMOVE_END
214+
215+
// STEP_START incrby_get_mget
216+
res8, err := rdb.HIncrBy(ctx, "bike:1:stats", "rides", 1).Result()
217+
218+
if err != nil {
219+
panic(err)
220+
}
221+
222+
fmt.Println(res8) // >>> 1
223+
224+
res9, err := rdb.HIncrBy(ctx, "bike:1:stats", "rides", 1).Result()
225+
226+
if err != nil {
227+
panic(err)
228+
}
229+
230+
fmt.Println(res9) // >>> 2
231+
232+
res10, err := rdb.HIncrBy(ctx, "bike:1:stats", "rides", 1).Result()
233+
234+
if err != nil {
235+
panic(err)
236+
}
237+
238+
fmt.Println(res10) // >>> 3
239+
240+
res11, err := rdb.HIncrBy(ctx, "bike:1:stats", "crashes", 1).Result()
241+
242+
if err != nil {
243+
panic(err)
244+
}
245+
246+
fmt.Println(res11) // >>> 1
247+
248+
res12, err := rdb.HIncrBy(ctx, "bike:1:stats", "owners", 1).Result()
249+
250+
if err != nil {
251+
panic(err)
252+
}
253+
254+
fmt.Println(res12) // >>> 1
255+
256+
res13, err := rdb.HGet(ctx, "bike:1:stats", "rides").Result()
257+
258+
if err != nil {
259+
panic(err)
260+
}
261+
262+
fmt.Println(res13) // >>> 3
263+
264+
res14, err := rdb.HMGet(ctx, "bike:1:stats", "crashes", "owners").Result()
265+
266+
if err != nil {
267+
panic(err)
268+
}
269+
270+
fmt.Println(res14) // >>> [1 1]
271+
// STEP_END
272+
273+
// Output:
274+
// 1
275+
// 2
276+
// 3
277+
// 1
278+
// 1
279+
// 3
280+
// [1 1]
281+
}

0 commit comments

Comments
 (0)