Skip to content

Instantly share code, notes, and snippets.

@rueian
Created November 4, 2023 05:29
Show Gist options
  • Save rueian/edd80e7cc08c1428fb479aabf0d1d707 to your computer and use it in GitHub Desktop.
Save rueian/edd80e7cc08c1428fb479aabf0d1d707 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"strconv"
"github.com/redis/rueidis"
)
func main() {
client, err := rueidis.NewClient(rueidis.ClientOption{InitAddress: []string{"127.0.0.1:6379"}})
if err != nil {
panic(err)
}
defer client.Close()
ctx := context.Background()
if err = client.Do(ctx, client.B().FtCreate().Index("debug_ft_search").OnHash().Prefix(1).
Prefix("debug_ft_search:").Schema().FieldName("merchant_id").Tag().Build()).Error(); err != nil {
fmt.Println(err)
}
for i := 0; i < 100; i++ {
if err = client.Do(ctx, client.B().Hset().Key("debug_ft_search:"+strconv.Itoa(i)).FieldValue().FieldValue("merchant_id", "1").Build()).Error(); err != nil {
panic(err)
}
}
for i := 0; i < 10; i++ {
fmt.Println(client.Do(ctx, client.B().FtSearch().Index("debug_ft_search").Query("@merchant_id:{1}").Nocontent().Scorer("BM25").Limit().OffsetNum(3, 3).Build()).AsFtSearch())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment