MCPcopy
hub / github.com/redis/go-redis / ExampleClient_query_em

Function ExampleClient_query_em

doctests/query_em_test.go:14–372  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func ExampleClient_query_em() {
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
24 // HIDE_END
25 // REMOVE_START
26 // start with fresh database
27 rdb.FlushDB(ctx)
28 rdb.FTDropIndex(ctx, "idx:bicycle")
29 rdb.FTDropIndex(ctx, "idx:email")
30 // REMOVE_END
31
32 _, err := rdb.FTCreate(ctx, "idx:bicycle",
33 &redis.FTCreateOptions{
34 OnJSON: true,
35 Prefix: []interface{}{"bicycle:"},
36 },
37 &redis.FieldSchema{
38 FieldName: "$.brand",
39 As: "brand",
40 FieldType: redis.SearchFieldTypeText,
41 },
42 &redis.FieldSchema{
43 FieldName: "$.model",
44 As: "model",
45 FieldType: redis.SearchFieldTypeText,
46 },
47 &redis.FieldSchema{
48 FieldName: "$.description",
49 As: "description",
50 FieldType: redis.SearchFieldTypeText,
51 },
52 &redis.FieldSchema{
53 FieldName: "$.price",
54 As: "price",
55 FieldType: redis.SearchFieldTypeNumeric,
56 },
57 &redis.FieldSchema{
58 FieldName: "$.condition",
59 As: "condition",
60 FieldType: redis.SearchFieldTypeTag,
61 },
62 ).Result()
63
64 if err != nil {
65 panic(err)
66 }
67
68 exampleJsons := []map[string]interface{}{
69 {
70 "pickup_zone": "POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, " +
71 "-74.0610 40.6678, -74.0610 40.7578))",

Callers

nothing calls this directly

Calls 7

FlushDBMethod · 0.65
FTDropIndexMethod · 0.65
ResultMethod · 0.65
FTCreateMethod · 0.65
JSONSetMethod · 0.65
FTSearchMethod · 0.65
FTSearchWithArgsMethod · 0.65

Tested by

no test coverage detected