Skip to content

Commit 526dc68

Browse files
authored
Merge branch 'master' into redissearch
2 parents fd47606 + 196fc9b commit 526dc68

37 files changed

+2198
-149
lines changed

.github/workflows/spellcheck.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- name: Checkout
99
uses: actions/checkout@v4
1010
- name: Check Spelling
11-
uses: rojopolis/spellcheck-github-actions@0.45.0
11+
uses: rojopolis/spellcheck-github-actions@0.46.0
1212
with:
1313
config_path: .github/spellcheck-settings.yml
1414
task_name: Markdown

commands_test.go

+54-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ var _ = Describe("Commands", func() {
217217

218218
killed := client.ClientKillByFilter(ctx, "MAXAGE", "1")
219219
Expect(killed.Err()).NotTo(HaveOccurred())
220-
Expect(killed.Val()).To(SatisfyAny(Equal(int64(2)), Equal(int64(3)), Equal(int64(4))))
220+
Expect(killed.Val()).To(BeNumerically(">=", 2))
221221

222222
select {
223223
case <-done:
@@ -532,6 +532,59 @@ var _ = Describe("Commands", func() {
532532
Expect(info.Val()).To(HaveLen(1))
533533
})
534534

535+
It("should Info Modules", Label("redis.info"), func() {
536+
SkipBeforeRedisMajor(8, "modules are included in info for Redis Version >= 8")
537+
info := client.Info(ctx)
538+
Expect(info.Err()).NotTo(HaveOccurred())
539+
Expect(info.Val()).NotTo(BeNil())
540+
541+
info = client.Info(ctx, "search")
542+
Expect(info.Err()).NotTo(HaveOccurred())
543+
Expect(info.Val()).To(ContainSubstring("search"))
544+
545+
info = client.Info(ctx, "modules")
546+
Expect(info.Err()).NotTo(HaveOccurred())
547+
Expect(info.Val()).To(ContainSubstring("search"))
548+
Expect(info.Val()).To(ContainSubstring("ReJSON"))
549+
Expect(info.Val()).To(ContainSubstring("timeseries"))
550+
Expect(info.Val()).To(ContainSubstring("bf"))
551+
552+
info = client.Info(ctx, "everything")
553+
Expect(info.Err()).NotTo(HaveOccurred())
554+
Expect(info.Val()).To(ContainSubstring("search"))
555+
Expect(info.Val()).To(ContainSubstring("ReJSON"))
556+
Expect(info.Val()).To(ContainSubstring("timeseries"))
557+
Expect(info.Val()).To(ContainSubstring("bf"))
558+
})
559+
560+
It("should InfoMap Modules", Label("redis.info"), func() {
561+
SkipBeforeRedisMajor(8, "modules are included in info for Redis Version >= 8")
562+
info := client.InfoMap(ctx)
563+
Expect(info.Err()).NotTo(HaveOccurred())
564+
Expect(info.Val()).NotTo(BeNil())
565+
566+
info = client.InfoMap(ctx, "search")
567+
Expect(info.Err()).NotTo(HaveOccurred())
568+
Expect(len(info.Val())).To(BeNumerically(">=", 2))
569+
Expect(info.Val()["search_version"]).ToNot(BeNil())
570+
571+
info = client.InfoMap(ctx, "modules")
572+
Expect(info.Err()).NotTo(HaveOccurred())
573+
val := info.Val()
574+
modules, ok := val["Modules"]
575+
Expect(ok).To(BeTrue())
576+
Expect(len(val)).To(BeNumerically(">=", 2))
577+
Expect(val["search_version"]).ToNot(BeNil())
578+
Expect(modules["search"]).ToNot(BeNil())
579+
Expect(modules["ReJSON"]).ToNot(BeNil())
580+
Expect(modules["timeseries"]).ToNot(BeNil())
581+
Expect(modules["bf"]).ToNot(BeNil())
582+
583+
info = client.InfoMap(ctx, "everything")
584+
Expect(info.Err()).NotTo(HaveOccurred())
585+
Expect(len(info.Val())).To(BeNumerically(">=", 10))
586+
})
587+
535588
It("should Info cpu", func() {
536589
info := client.Info(ctx, "cpu")
537590
Expect(info.Err()).NotTo(HaveOccurred())

doctests/geo_index_test.go

+206
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
// EXAMPLE: geoindex
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_geoindex() {
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+
Protocol: 2,
22+
})
23+
// REMOVE_START
24+
rdb.FTDropIndex(ctx, "productidx")
25+
rdb.FTDropIndex(ctx, "geomidx")
26+
rdb.Del(ctx, "product:46885", "product:46886", "shape:1", "shape:2", "shape:3", "shape:4")
27+
// REMOVE_END
28+
29+
// STEP_START create_geo_idx
30+
geoCreateResult, err := rdb.FTCreate(ctx,
31+
"productidx",
32+
&redis.FTCreateOptions{
33+
OnJSON: true,
34+
Prefix: []interface{}{"product:"},
35+
},
36+
&redis.FieldSchema{
37+
FieldName: "$.location",
38+
As: "location",
39+
FieldType: redis.SearchFieldTypeGeo,
40+
},
41+
).Result()
42+
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
fmt.Println(geoCreateResult) // >>> OK
48+
// STEP_END
49+
50+
// STEP_START add_geo_json
51+
prd46885 := map[string]interface{}{
52+
"description": "Navy Blue Slippers",
53+
"price": 45.99,
54+
"city": "Denver",
55+
"location": "-104.991531, 39.742043",
56+
}
57+
58+
gjResult1, err := rdb.JSONSet(ctx, "product:46885", "$", prd46885).Result()
59+
60+
if err != nil {
61+
panic(err)
62+
}
63+
64+
fmt.Println(gjResult1) // >>> OK
65+
66+
prd46886 := map[string]interface{}{
67+
"description": "Bright Green Socks",
68+
"price": 25.50,
69+
"city": "Fort Collins",
70+
"location": "-105.0618814,40.5150098",
71+
}
72+
73+
gjResult2, err := rdb.JSONSet(ctx, "product:46886", "$", prd46886).Result()
74+
75+
if err != nil {
76+
panic(err)
77+
}
78+
79+
fmt.Println(gjResult2) // >>> OK
80+
// STEP_END
81+
82+
// STEP_START geo_query
83+
geoQueryResult, err := rdb.FTSearch(ctx, "productidx",
84+
"@location:[-104.800644 38.846127 100 mi]",
85+
).Result()
86+
87+
if err != nil {
88+
panic(err)
89+
}
90+
91+
fmt.Println(geoQueryResult)
92+
// >>> {1 [{product:46885...
93+
// STEP_END
94+
95+
// STEP_START create_gshape_idx
96+
geomCreateResult, err := rdb.FTCreate(ctx, "geomidx",
97+
&redis.FTCreateOptions{
98+
OnJSON: true,
99+
Prefix: []interface{}{"shape:"},
100+
},
101+
&redis.FieldSchema{
102+
FieldName: "$.name",
103+
As: "name",
104+
FieldType: redis.SearchFieldTypeText,
105+
},
106+
&redis.FieldSchema{
107+
FieldName: "$.geom",
108+
As: "geom",
109+
FieldType: redis.SearchFieldTypeGeoShape,
110+
GeoShapeFieldType: "FLAT",
111+
},
112+
).Result()
113+
114+
if err != nil {
115+
panic(err)
116+
}
117+
118+
fmt.Println(geomCreateResult) // >>> OK
119+
// STEP_END
120+
121+
// STEP_START add_gshape_json
122+
shape1 := map[string]interface{}{
123+
"name": "Green Square",
124+
"geom": "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))",
125+
}
126+
127+
gmjResult1, err := rdb.JSONSet(ctx, "shape:1", "$", shape1).Result()
128+
129+
if err != nil {
130+
panic(err)
131+
}
132+
133+
fmt.Println(gmjResult1) // >>> OK
134+
135+
shape2 := map[string]interface{}{
136+
"name": "Red Rectangle",
137+
"geom": "POLYGON ((2 2.5, 2 3.5, 3.5 3.5, 3.5 2.5, 2 2.5))",
138+
}
139+
140+
gmjResult2, err := rdb.JSONSet(ctx, "shape:2", "$", shape2).Result()
141+
142+
if err != nil {
143+
panic(err)
144+
}
145+
146+
fmt.Println(gmjResult2) // >>> OK
147+
148+
shape3 := map[string]interface{}{
149+
"name": "Blue Triangle",
150+
"geom": "POLYGON ((3.5 1, 3.75 2, 4 1, 3.5 1))",
151+
}
152+
153+
gmjResult3, err := rdb.JSONSet(ctx, "shape:3", "$", shape3).Result()
154+
155+
if err != nil {
156+
panic(err)
157+
}
158+
159+
fmt.Println(gmjResult3) // >>> OK
160+
161+
shape4 := map[string]interface{}{
162+
"name": "Purple Point",
163+
"geom": "POINT (2 2)",
164+
}
165+
166+
gmjResult4, err := rdb.JSONSet(ctx, "shape:4", "$", shape4).Result()
167+
168+
if err != nil {
169+
panic(err)
170+
}
171+
172+
fmt.Println(gmjResult4) // >>> OK
173+
// STEP_END
174+
175+
// STEP_START gshape_query
176+
geomQueryResult, err := rdb.FTSearchWithArgs(ctx, "geomidx",
177+
"(-@name:(Green Square) @geom:[WITHIN $qshape])",
178+
&redis.FTSearchOptions{
179+
Params: map[string]interface{}{
180+
"qshape": "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))",
181+
},
182+
DialectVersion: 4,
183+
Limit: 1,
184+
},
185+
).Result()
186+
187+
if err != nil {
188+
panic(err)
189+
}
190+
191+
fmt.Println(geomQueryResult)
192+
// >>> {1 [{shape:4...
193+
// STEP_END
194+
195+
// Output:
196+
// OK
197+
// OK
198+
// OK
199+
// {1 [{product:46885 <nil> <nil> <nil> map[$:{"city":"Denver","description":"Navy Blue Slippers","location":"-104.991531, 39.742043","price":45.99}]}]}
200+
// OK
201+
// OK
202+
// OK
203+
// OK
204+
// OK
205+
// {1 [{shape:4 <nil> <nil> <nil> map[$:[{"geom":"POINT (2 2)","name":"Purple Point"}]]}]}
206+
}

doctests/list_tutorial_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func ExampleClient_ltrim() {
388388
// REMOVE_END
389389

390390
// STEP_START ltrim
391-
res27, err := rdb.LPush(ctx, "bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5").Result()
391+
res27, err := rdb.RPush(ctx, "bikes:repairs", "bike:1", "bike:2", "bike:3", "bike:4", "bike:5").Result()
392392

393393
if err != nil {
394394
panic(err)
@@ -410,13 +410,13 @@ func ExampleClient_ltrim() {
410410
panic(err)
411411
}
412412

413-
fmt.Println(res29) // >>> [bike:5 bike:4 bike:3]
413+
fmt.Println(res29) // >>> [bike:1 bike:2 bike:3]
414414
// STEP_END
415415

416416
// Output:
417417
// 5
418418
// OK
419-
// [bike:5 bike:4 bike:3]
419+
// [bike:1 bike:2 bike:3]
420420
}
421421

422422
func ExampleClient_ltrim_end_of_list() {

0 commit comments

Comments
 (0)