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

Function ExampleClient_query_geo

doctests/query_geo_test.go:13–329  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func ExampleClient_query_geo() {
14 ctx := context.Background()
15
16 rdb := redis.NewClient(&redis.Options{
17 Addr: "localhost:6379",
18 Password: "", // no password docs
19 DB: 0, // use default DB
20 Protocol: 2,
21 })
22 // HIDE_END
23 // REMOVE_START
24 // start with fresh database
25 rdb.FlushDB(ctx)
26 rdb.FTDropIndex(ctx, "idx:bicycle")
27 // REMOVE_END
28
29 _, err := rdb.FTCreate(ctx, "idx:bicycle",
30 &redis.FTCreateOptions{
31 OnJSON: true,
32 Prefix: []interface{}{"bicycle:"},
33 },
34 &redis.FieldSchema{
35 FieldName: "$.brand",
36 As: "brand",
37 FieldType: redis.SearchFieldTypeText,
38 },
39 &redis.FieldSchema{
40 FieldName: "$.model",
41 As: "model",
42 FieldType: redis.SearchFieldTypeText,
43 },
44 &redis.FieldSchema{
45 FieldName: "$.description",
46 As: "description",
47 FieldType: redis.SearchFieldTypeText,
48 },
49 &redis.FieldSchema{
50 FieldName: "$.price",
51 As: "price",
52 FieldType: redis.SearchFieldTypeNumeric,
53 },
54 &redis.FieldSchema{
55 FieldName: "$.condition",
56 As: "condition",
57 FieldType: redis.SearchFieldTypeTag,
58 },
59 &redis.FieldSchema{
60 FieldName: "$.store_location",
61 As: "store_location",
62 FieldType: redis.SearchFieldTypeGeo,
63 },
64 &redis.FieldSchema{
65 FieldName: "$.pickup_zone",
66 As: "pickup_zone",
67 FieldType: redis.SearchFieldTypeGeoShape,
68 GeoShapeFieldType: "FLAT",
69 },
70 ).Result()

Callers

nothing calls this directly

Calls 7

SliceMethod · 0.80
FlushDBMethod · 0.65
FTDropIndexMethod · 0.65
ResultMethod · 0.65
FTCreateMethod · 0.65
JSONSetMethod · 0.65
FTSearchWithArgsMethod · 0.65

Tested by

no test coverage detected