mirror of
https://github.com/redis/go-redis.git
synced 2025-06-05 06:42:39 +03:00
Merge branch 'master' into ndyakov/update-readme-discord
This commit is contained in:
commit
6e63b72f13
@ -3831,7 +3831,8 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// MapStringInterfaceCmd represents a command that returns a map of strings to interface{}.
|
||||
|
||||
// MapMapStringInterfaceCmd represents a command that returns a map of strings to interface{}.
|
||||
type MapMapStringInterfaceCmd struct {
|
||||
baseCmd
|
||||
val map[string]interface{}
|
||||
|
@ -330,7 +330,7 @@ func (info LibraryInfo) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Hello Set the resp protocol used.
|
||||
// Hello sets the resp protocol used.
|
||||
func (c statefulCmdable) Hello(ctx context.Context,
|
||||
ver int, username, password, clientName string,
|
||||
) *MapStringInterfaceCmd {
|
||||
|
@ -227,3 +227,107 @@ func ExampleClient_search_json() {
|
||||
// London - 1
|
||||
// Tel Aviv - 2
|
||||
}
|
||||
|
||||
func ExampleClient_search_hash() {
|
||||
ctx := context.Background()
|
||||
|
||||
rdb := redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
Password: "", // no password docs
|
||||
DB: 0, // use default DB
|
||||
Protocol: 2,
|
||||
})
|
||||
|
||||
// REMOVE_START
|
||||
rdb.Del(ctx, "huser:1", "huser:2", "huser:3")
|
||||
rdb.FTDropIndex(ctx, "hash-idx:users")
|
||||
// REMOVE_END
|
||||
|
||||
// STEP_START make_hash_index
|
||||
_, err := rdb.FTCreate(
|
||||
ctx,
|
||||
"hash-idx:users",
|
||||
// Options:
|
||||
&redis.FTCreateOptions{
|
||||
OnHash: true,
|
||||
Prefix: []interface{}{"huser:"},
|
||||
},
|
||||
// Index schema fields:
|
||||
&redis.FieldSchema{
|
||||
FieldName: "name",
|
||||
FieldType: redis.SearchFieldTypeText,
|
||||
},
|
||||
&redis.FieldSchema{
|
||||
FieldName: "city",
|
||||
FieldType: redis.SearchFieldTypeTag,
|
||||
},
|
||||
&redis.FieldSchema{
|
||||
FieldName: "age",
|
||||
FieldType: redis.SearchFieldTypeNumeric,
|
||||
},
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// STEP_END
|
||||
|
||||
user1 := map[string]interface{}{
|
||||
"name": "Paul John",
|
||||
"email": "paul.john@example.com",
|
||||
"age": 42,
|
||||
"city": "London",
|
||||
}
|
||||
|
||||
user2 := map[string]interface{}{
|
||||
"name": "Eden Zamir",
|
||||
"email": "eden.zamir@example.com",
|
||||
"age": 29,
|
||||
"city": "Tel Aviv",
|
||||
}
|
||||
|
||||
user3 := map[string]interface{}{
|
||||
"name": "Paul Zamir",
|
||||
"email": "paul.zamir@example.com",
|
||||
"age": 35,
|
||||
"city": "Tel Aviv",
|
||||
}
|
||||
|
||||
// STEP_START add_hash_data
|
||||
_, err = rdb.HSet(ctx, "huser:1", user1).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = rdb.HSet(ctx, "huser:2", user2).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = rdb.HSet(ctx, "huser:3", user3).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// STEP_END
|
||||
|
||||
// STEP_START query1_hash
|
||||
findPaulHashResult, err := rdb.FTSearch(
|
||||
ctx,
|
||||
"hash-idx:users",
|
||||
"Paul @age:[30 40]",
|
||||
).Result()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println(findPaulHashResult)
|
||||
// >>> {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv...
|
||||
// STEP_END
|
||||
|
||||
// Output:
|
||||
// {1 [{huser:3 <nil> <nil> <nil> map[age:35 city:Tel Aviv email:paul.zamir@example.com name:Paul Zamir]}]}
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ func (c cmdable) HGetEX(ctx context.Context, key string, fields ...string) *Stri
|
||||
return cmd
|
||||
}
|
||||
|
||||
// ExpirationType represents an expiration option for the HGETEX command.
|
||||
// HGetEXExpirationType represents an expiration option for the HGETEX command.
|
||||
type HGetEXExpirationType string
|
||||
|
||||
const (
|
||||
|
Loading…
x
Reference in New Issue
Block a user