Created
November 4, 2023 05:29
-
-
Save rueian/edd80e7cc08c1428fb479aabf0d1d707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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