Skip to content

Commit 6e63b72

Browse files
Merge branch 'master' into ndyakov/update-readme-discord
2 parents f6f917a + f7780dd commit 6e63b72

File tree

4 files changed

+108
-3
lines changed

4 files changed

+108
-3
lines changed

command.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3831,7 +3831,8 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error {
38313831
}
38323832

38333833
// -----------------------------------------------------------------------
3834-
// MapStringInterfaceCmd represents a command that returns a map of strings to interface{}.
3834+
3835+
// MapMapStringInterfaceCmd represents a command that returns a map of strings to interface{}.
38353836
type MapMapStringInterfaceCmd struct {
38363837
baseCmd
38373838
val map[string]interface{}

commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func (info LibraryInfo) Validate() error {
330330
return nil
331331
}
332332

333-
// Hello Set the resp protocol used.
333+
// Hello sets the resp protocol used.
334334
func (c statefulCmdable) Hello(ctx context.Context,
335335
ver int, username, password, clientName string,
336336
) *MapStringInterfaceCmd {

doctests/home_json_example_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,107 @@ func ExampleClient_search_json() {
227227
// London - 1
228228
// Tel Aviv - 2
229229
}
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": "[email protected]",
278+
"age": 42,
279+
"city": "London",
280+
}
281+
282+
user2 := map[string]interface{}{
283+
"name": "Eden Zamir",
284+
"email": "[email protected]",
285+
"age": 29,
286+
"city": "Tel Aviv",
287+
}
288+
289+
user3 := map[string]interface{}{
290+
"name": "Paul Zamir",
291+
"email": "[email protected]",
292+
"age": 35,
293+
"city": "Tel Aviv",
294+
}
295+
296+
// STEP_START add_hash_data
297+
_, err = rdb.HSet(ctx, "huser:1", user1).Result()
298+
299+
if err != nil {
300+
panic(err)
301+
}
302+
303+
_, err = rdb.HSet(ctx, "huser:2", user2).Result()
304+
305+
if err != nil {
306+
panic(err)
307+
}
308+
309+
_, err = rdb.HSet(ctx, "huser:3", user3).Result()
310+
311+
if err != nil {
312+
panic(err)
313+
}
314+
// STEP_END
315+
316+
// STEP_START query1_hash
317+
findPaulHashResult, err := rdb.FTSearch(
318+
ctx,
319+
"hash-idx:users",
320+
"Paul @age:[30 40]",
321+
).Result()
322+
323+
if err != nil {
324+
panic(err)
325+
}
326+
327+
fmt.Println(findPaulHashResult)
328+
// >>> {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv...
329+
// STEP_END
330+
331+
// Output:
332+
// {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv email:[email protected] name:Paul Zamir]}]}
333+
}

hash_commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ func (c cmdable) HGetEX(ctx context.Context, key string, fields ...string) *Stri
480480
return cmd
481481
}
482482

483-
// ExpirationType represents an expiration option for the HGETEX command.
483+
// HGetEXExpirationType represents an expiration option for the HGETEX command.
484484
type HGetEXExpirationType string
485485

486486
const (

0 commit comments

Comments
 (0)