Skip to content

Commit

Permalink
Merge branch 'master' into redissearch
Browse files Browse the repository at this point in the history
  • Loading branch information
ndyakov authored Feb 17, 2025
2 parents fd47606 + 196fc9b commit 526dc68
Show file tree
Hide file tree
Showing 37 changed files with 2,198 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/spellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Check Spelling
uses: rojopolis/spellcheck-github-actions@0.45.0
uses: rojopolis/spellcheck-github-actions@0.46.0
with:
config_path: .github/spellcheck-settings.yml
task_name: Markdown
55 changes: 54 additions & 1 deletion commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ var _ = Describe("Commands", func() {

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

select {
case <-done:
Expand Down Expand Up @@ -532,6 +532,59 @@ var _ = Describe("Commands", func() {
Expect(info.Val()).To(HaveLen(1))
})

It("should Info Modules", Label("redis.info"), func() {
SkipBeforeRedisMajor(8, "modules are included in info for Redis Version >= 8")
info := client.Info(ctx)
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).NotTo(BeNil())

info = client.Info(ctx, "search")
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).To(ContainSubstring("search"))

info = client.Info(ctx, "modules")
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).To(ContainSubstring("search"))
Expect(info.Val()).To(ContainSubstring("ReJSON"))
Expect(info.Val()).To(ContainSubstring("timeseries"))
Expect(info.Val()).To(ContainSubstring("bf"))

info = client.Info(ctx, "everything")
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).To(ContainSubstring("search"))
Expect(info.Val()).To(ContainSubstring("ReJSON"))
Expect(info.Val()).To(ContainSubstring("timeseries"))
Expect(info.Val()).To(ContainSubstring("bf"))
})

It("should InfoMap Modules", Label("redis.info"), func() {
SkipBeforeRedisMajor(8, "modules are included in info for Redis Version >= 8")
info := client.InfoMap(ctx)
Expect(info.Err()).NotTo(HaveOccurred())
Expect(info.Val()).NotTo(BeNil())

info = client.InfoMap(ctx, "search")
Expect(info.Err()).NotTo(HaveOccurred())
Expect(len(info.Val())).To(BeNumerically(">=", 2))
Expect(info.Val()["search_version"]).ToNot(BeNil())

info = client.InfoMap(ctx, "modules")
Expect(info.Err()).NotTo(HaveOccurred())
val := info.Val()
modules, ok := val["Modules"]
Expect(ok).To(BeTrue())
Expect(len(val)).To(BeNumerically(">=", 2))
Expect(val["search_version"]).ToNot(BeNil())
Expect(modules["search"]).ToNot(BeNil())
Expect(modules["ReJSON"]).ToNot(BeNil())
Expect(modules["timeseries"]).ToNot(BeNil())
Expect(modules["bf"]).ToNot(BeNil())

info = client.InfoMap(ctx, "everything")
Expect(info.Err()).NotTo(HaveOccurred())
Expect(len(info.Val())).To(BeNumerically(">=", 10))
})

It("should Info cpu", func() {
info := client.Info(ctx, "cpu")
Expect(info.Err()).NotTo(HaveOccurred())
Expand Down
206 changes: 206 additions & 0 deletions doctests/geo_index_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
// EXAMPLE: geoindex
// HIDE_START
package example_commands_test

import (
"context"
"fmt"

"github.com/redis/go-redis/v9"
)

// HIDE_END

func ExampleClient_geoindex() {
ctx := context.Background()

rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password docs
DB: 0, // use default DB
Protocol: 2,
})
// REMOVE_START
rdb.FTDropIndex(ctx, "productidx")
rdb.FTDropIndex(ctx, "geomidx")
rdb.Del(ctx, "product:46885", "product:46886", "shape:1", "shape:2", "shape:3", "shape:4")
// REMOVE_END

// STEP_START create_geo_idx
geoCreateResult, err := rdb.FTCreate(ctx,
"productidx",
&redis.FTCreateOptions{
OnJSON: true,
Prefix: []interface{}{"product:"},
},
&redis.FieldSchema{
FieldName: "$.location",
As: "location",
FieldType: redis.SearchFieldTypeGeo,
},
).Result()

if err != nil {
panic(err)
}

fmt.Println(geoCreateResult) // >>> OK
// STEP_END

// STEP_START add_geo_json
prd46885 := map[string]interface{}{
"description": "Navy Blue Slippers",
"price": 45.99,
"city": "Denver",
"location": "-104.991531, 39.742043",
}

gjResult1, err := rdb.JSONSet(ctx, "product:46885", "$", prd46885).Result()

if err != nil {
panic(err)
}

fmt.Println(gjResult1) // >>> OK

prd46886 := map[string]interface{}{
"description": "Bright Green Socks",
"price": 25.50,
"city": "Fort Collins",
"location": "-105.0618814,40.5150098",
}

gjResult2, err := rdb.JSONSet(ctx, "product:46886", "$", prd46886).Result()

if err != nil {
panic(err)
}

fmt.Println(gjResult2) // >>> OK
// STEP_END

// STEP_START geo_query
geoQueryResult, err := rdb.FTSearch(ctx, "productidx",
"@location:[-104.800644 38.846127 100 mi]",
).Result()

if err != nil {
panic(err)
}

fmt.Println(geoQueryResult)
// >>> {1 [{product:46885...
// STEP_END

// STEP_START create_gshape_idx
geomCreateResult, err := rdb.FTCreate(ctx, "geomidx",
&redis.FTCreateOptions{
OnJSON: true,
Prefix: []interface{}{"shape:"},
},
&redis.FieldSchema{
FieldName: "$.name",
As: "name",
FieldType: redis.SearchFieldTypeText,
},
&redis.FieldSchema{
FieldName: "$.geom",
As: "geom",
FieldType: redis.SearchFieldTypeGeoShape,
GeoShapeFieldType: "FLAT",
},
).Result()

if err != nil {
panic(err)
}

fmt.Println(geomCreateResult) // >>> OK
// STEP_END

// STEP_START add_gshape_json
shape1 := map[string]interface{}{
"name": "Green Square",
"geom": "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))",
}

gmjResult1, err := rdb.JSONSet(ctx, "shape:1", "$", shape1).Result()

if err != nil {
panic(err)
}

fmt.Println(gmjResult1) // >>> OK

shape2 := map[string]interface{}{
"name": "Red Rectangle",
"geom": "POLYGON ((2 2.5, 2 3.5, 3.5 3.5, 3.5 2.5, 2 2.5))",
}

gmjResult2, err := rdb.JSONSet(ctx, "shape:2", "$", shape2).Result()

if err != nil {
panic(err)
}

fmt.Println(gmjResult2) // >>> OK

shape3 := map[string]interface{}{
"name": "Blue Triangle",
"geom": "POLYGON ((3.5 1, 3.75 2, 4 1, 3.5 1))",
}

gmjResult3, err := rdb.JSONSet(ctx, "shape:3", "$", shape3).Result()

if err != nil {
panic(err)
}

fmt.Println(gmjResult3) // >>> OK

shape4 := map[string]interface{}{
"name": "Purple Point",
"geom": "POINT (2 2)",
}

gmjResult4, err := rdb.JSONSet(ctx, "shape:4", "$", shape4).Result()

if err != nil {
panic(err)
}

fmt.Println(gmjResult4) // >>> OK
// STEP_END

// STEP_START gshape_query
geomQueryResult, err := rdb.FTSearchWithArgs(ctx, "geomidx",
"(-@name:(Green Square) @geom:[WITHIN $qshape])",
&redis.FTSearchOptions{
Params: map[string]interface{}{
"qshape": "POLYGON ((1 1, 1 3, 3 3, 3 1, 1 1))",
},
DialectVersion: 4,
Limit: 1,
},
).Result()

if err != nil {
panic(err)
}

fmt.Println(geomQueryResult)
// >>> {1 [{shape:4...
// STEP_END

// Output:
// OK
// OK
// OK
// {1 [{product:46885 <nil> <nil> <nil> map[$:{"city":"Denver","description":"Navy Blue Slippers","location":"-104.991531, 39.742043","price":45.99}]}]}
// OK
// OK
// OK
// OK
// OK
// {1 [{shape:4 <nil> <nil> <nil> map[$:[{"geom":"POINT (2 2)","name":"Purple Point"}]]}]}
}
6 changes: 3 additions & 3 deletions doctests/list_tutorial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func ExampleClient_ltrim() {
// REMOVE_END

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

if err != nil {
panic(err)
Expand All @@ -410,13 +410,13 @@ func ExampleClient_ltrim() {
panic(err)
}

fmt.Println(res29) // >>> [bike:5 bike:4 bike:3]
fmt.Println(res29) // >>> [bike:1 bike:2 bike:3]
// STEP_END

// Output:
// 5
// OK
// [bike:5 bike:4 bike:3]
// [bike:1 bike:2 bike:3]
}

func ExampleClient_ltrim_end_of_list() {
Expand Down
Loading

0 comments on commit 526dc68

Please sign in to comment.