| 229 | } |
| 230 | |
| 231 | func ExampleClient_search_hash() { |
| 232 | ctx := context.Background() |
| 233 | |
| 234 | rdb := redis.NewClient(&redis.Options{ |
| 235 | Addr: "localhost:6379", |
| 236 | Password: "", // no password docs |
| 237 | DB: 0, // use default DB |
| 238 | Protocol: 2, |
| 239 | }) |
| 240 | |
| 241 | // REMOVE_START |
| 242 | rdb.Del(ctx, "huser:1", "huser:2", "huser:3") |
| 243 | rdb.FTDropIndex(ctx, "hash-idx:users") |
| 244 | // REMOVE_END |
| 245 | |
| 246 | // STEP_START make_hash_index |
| 247 | _, err := rdb.FTCreate( |
| 248 | ctx, |
| 249 | "hash-idx:users", |
| 250 | // Options: |
| 251 | &redis.FTCreateOptions{ |
| 252 | OnHash: true, |
| 253 | Prefix: []interface{}{"huser:"}, |
| 254 | }, |
| 255 | // Index schema fields: |
| 256 | &redis.FieldSchema{ |
| 257 | FieldName: "name", |
| 258 | FieldType: redis.SearchFieldTypeText, |
| 259 | }, |
| 260 | &redis.FieldSchema{ |
| 261 | FieldName: "city", |
| 262 | FieldType: redis.SearchFieldTypeTag, |
| 263 | }, |
| 264 | &redis.FieldSchema{ |
| 265 | FieldName: "age", |
| 266 | FieldType: redis.SearchFieldTypeNumeric, |
| 267 | }, |
| 268 | ).Result() |
| 269 | |
| 270 | if err != nil { |
| 271 | panic(err) |
| 272 | } |
| 273 | // STEP_END |
| 274 | |
| 275 | user1 := map[string]interface{}{ |
| 276 | "name": "Paul John", |
| 277 | "email": "paul.john@example.com", |
| 278 | "age": 42, |
| 279 | "city": "London", |
| 280 | } |
| 281 | |
| 282 | user2 := map[string]interface{}{ |
| 283 | "name": "Eden Zamir", |
| 284 | "email": "eden.zamir@example.com", |
| 285 | "age": 29, |
| 286 | "city": "Tel Aviv", |
| 287 | } |
| 288 | |