Skip to content

Instantly share code, notes, and snippets.

@rueian
Created May 15, 2023 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rueian/82a3808d17d53dc35dbc9de71fb686e6 to your computer and use it in GitHub Desktop.
Save rueian/82a3808d17d53dc35dbc9de71fb686e6 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"github.com/redis/rueidis"
)
func main() {
client, err := rueidis.NewClient(rueidis.ClientOption{InitAddress: []string{"127.0.0.1:6377"}})
if err != nil {
panic(err)
}
defer client.Close()
ctx := context.Background()
if err = client.Do(ctx, client.B().FtCreate().Index("users").OnHash().Prefix(1).
Prefix("users:").Schema().FieldName("groups").Tag().Separator(",").Build()).Error(); err != nil {
fmt.Println(err)
}
if err = client.Do(ctx, client.B().Hset().Key("users:1").FieldValue().FieldValue("groups", "1,2,3").Build()).Error(); err != nil {
fmt.Println(err)
}
if err = client.Do(ctx, client.B().Hset().Key("users:a").FieldValue().FieldValue("groups", "a,b,c").Build()).Error(); err != nil {
fmt.Println(err)
}
fmt.Println(client.Do(ctx, client.B().FtSearch().Index("users").Query("@groups:{ 1 }").Build()).AsFtSearch())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment