HIDE_END
()
| 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 | |
| 24 | // REMOVE_START |
| 25 | // make sure we are working with fresh database |
| 26 | rdb.FlushDB(ctx) |
| 27 | rdb.FTDropIndex(ctx, "productidx") |
| 28 | rdb.FTDropIndex(ctx, "geomidx") |
| 29 | rdb.Del(ctx, "product:46885", "product:46886", "shape:1", "shape:2", "shape:3", "shape:4") |
| 30 | // REMOVE_END |
| 31 | |
| 32 | // STEP_START create_geo_idx |
| 33 | geoCreateResult, err := rdb.FTCreate(ctx, |
| 34 | "productidx", |
| 35 | &redis.FTCreateOptions{ |
| 36 | OnJSON: true, |
| 37 | Prefix: []interface{}{"product:"}, |
| 38 | }, |
| 39 | &redis.FieldSchema{ |
| 40 | FieldName: "$.location", |
| 41 | As: "location", |
| 42 | FieldType: redis.SearchFieldTypeGeo, |
| 43 | }, |
| 44 | ).Result() |
| 45 | |
| 46 | if err != nil { |
| 47 | panic(err) |
| 48 | } |
| 49 | |
| 50 | fmt.Println(geoCreateResult) // >>> OK |
| 51 | // STEP_END |
| 52 | |
| 53 | // STEP_START add_geo_json |
| 54 | prd46885 := map[string]interface{}{ |
| 55 | "description": "Navy Blue Slippers", |
| 56 | "price": 45.99, |
| 57 | "city": "Denver", |
| 58 | "location": "-104.991531, 39.742043", |
| 59 | } |
| 60 | |
| 61 | gjResult1, err := rdb.JSONSet(ctx, "product:46885", "$", prd46885).Result() |
| 62 | |
| 63 | if err != nil { |
| 64 | panic(err) |
| 65 | } |
| 66 | |
| 67 | fmt.Println(gjResult1) // >>> OK |
| 68 | |
| 69 | prd46886 := map[string]interface{}{ |
| 70 | "description": "Bright Green Socks", |
| 71 | "price": 25.50, |
nothing calls this directly
no test coverage detected