Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release-0.6' into zhenghaoz/clic…
Browse files Browse the repository at this point in the history
…khouse
  • Loading branch information
zhenghaoz committed Nov 1, 2024
2 parents df299ca + bb07142 commit 212c94c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
4 changes: 3 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,11 @@ func (suite *GorseClientTestSuite) TestItems() {

func (suite *GorseClientTestSuite) hSet(collection, subset string, scores []Score) {
for _, score := range scores {
err := suite.redis.HSet(context.TODO(), "documents:"+collection+":"+subset+":"+score.Id,
err := suite.redis.HSet(context.TODO(), "scores:"+collection+":"+subset+":"+score.Id,
"collection_ns", base64.RawStdEncoding.EncodeToString([]byte("_")),
"collection", collection,
"subset", subset,
"namespace", base64.RawStdEncoding.EncodeToString([]byte("_")),
"id", score.Id,
"score", score.Score,
"is_hidden", 0,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require (
github.com/prometheus/client_golang v1.13.0
github.com/rakyll/statik v0.1.7
github.com/redis/go-redis/extra/redisotel/v9 v9.5.3
github.com/redis/go-redis/v9 v9.7.0-beta.1
github.com/redis/go-redis/v9 v9.7.0
github.com/samber/lo v1.38.1
github.com/schollz/progressbar/v3 v3.9.0
github.com/sclevine/yj v0.0.0-20210612025309-737bdf40a5d1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ github.com/redis/go-redis/extra/rediscmd/v9 v9.5.3 h1:1/BDligzCa40GTllkDnY3Y5DTH
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.3/go.mod h1:3dZmcLn3Qw6FLlWASn1g4y+YO9ycEFUOM+bhBmzLVKQ=
github.com/redis/go-redis/extra/redisotel/v9 v9.5.3 h1:kuvuJL/+MZIEdvtb/kTBRiRgYaOmx1l+lYJyVdrRUOs=
github.com/redis/go-redis/extra/redisotel/v9 v9.5.3/go.mod h1:7f/FMrf5RRRVHXgfk7CzSVzXHiWeuOQUu2bsVqWoa+g=
github.com/redis/go-redis/v9 v9.7.0-beta.1 h1:x8FaPEIjBIjzkO3irDARTa/yemsNeHmni16UcVK/ttE=
github.com/redis/go-redis/v9 v9.7.0-beta.1/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
Expand Down
47 changes: 18 additions & 29 deletions storage/cache/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,21 @@ func (r *Redis) Init() error {
}
// create index
if !lo.Contains(indices, r.ScoresTable()) {
_, err = r.client.Do(context.TODO(), "FT.CREATE", r.ScoresTable(),
"ON", "HASH", "PREFIX", "1", r.ScoresTable()+":", "SCHEMA",
"collection_ns", "TAG",
"collection", "TAG",
"subset", "TAG",
"namespace", "TAG",
"id", "TAG",
"score", "NUMERIC", "SORTABLE",
"is_hidden", "NUMERIC",
"categories", "TAG", "SEPARATOR", ";",
"timestamp", "NUMERIC", "SORTABLE").
Result()
// Blocked by https://github.com/redis/go-redis/issues/3150
//_, err = r.client.FTCreate(context.TODO(), r.ScoresTable(),
// &redis.FTCreateOptions{
// OnHash: true,
// Prefix: []any{r.ScoresTable() + ":"},
// },
// &redis.FieldSchema{FieldName: "collection", FieldType: redis.SearchFieldTypeTag},
// &redis.FieldSchema{FieldName: "subset", FieldType: redis.SearchFieldTypeTag},
// &redis.FieldSchema{FieldName: "id", FieldType: redis.SearchFieldTypeTag},
// &redis.FieldSchema{FieldName: "score", FieldType: redis.SearchFieldTypeNumeric, Sortable: true},
// &redis.FieldSchema{FieldName: "is_hidden", FieldType: redis.SearchFieldTypeNumeric},
// &redis.FieldSchema{FieldName: "categories", FieldType: redis.SearchFieldTypeTag, Seperator: ";"},
// &redis.FieldSchema{FieldName: "timestamp", FieldType: redis.SearchFieldTypeNumeric, Sortable: true},
//).Result()
_, err = r.client.FTCreate(context.TODO(), r.ScoresTable(),
&redis.FTCreateOptions{
OnHash: true,
Prefix: []any{r.ScoresTable() + ":"},
},
&redis.FieldSchema{FieldName: "collection_ns", FieldType: redis.SearchFieldTypeTag},
&redis.FieldSchema{FieldName: "collection", FieldType: redis.SearchFieldTypeTag},
&redis.FieldSchema{FieldName: "subset", FieldType: redis.SearchFieldTypeTag},
&redis.FieldSchema{FieldName: "namespace", FieldType: redis.SearchFieldTypeTag},
&redis.FieldSchema{FieldName: "id", FieldType: redis.SearchFieldTypeTag},
&redis.FieldSchema{FieldName: "score", FieldType: redis.SearchFieldTypeNumeric, Sortable: true},
&redis.FieldSchema{FieldName: "is_hidden", FieldType: redis.SearchFieldTypeNumeric},
&redis.FieldSchema{FieldName: "categories", FieldType: redis.SearchFieldTypeTag, Separator: ";"},
&redis.FieldSchema{FieldName: "timestamp", FieldType: redis.SearchFieldTypeNumeric, Sortable: true},
).Result()
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -246,14 +235,14 @@ func (r *Redis) Remain(ctx context.Context, name string) (int64, error) {
return r.client.ZCard(ctx, r.Key(name)).Result()
}

func (r *Redis) documentKey(collection, subset, value string) string {
return r.ScoresTable() + ":" + collection + ":" + subset + ":" + value
func (r *Redis) documentKey(namespace, collection, subset, value string) string {
return r.ScoresTable() + ":" + namespace + ":" + collection + ":" + subset + ":" + value
}

func (r *Redis) AddScores(ctx context.Context, collectionNamespace, collectionName, collectionSubset string, documents []Score) error {
p := r.client.Pipeline()
for _, document := range documents {
p.HSet(ctx, r.documentKey(collectionName, collectionSubset, document.Id),
p.HSet(ctx, r.documentKey(collectionNamespace, collectionName, collectionSubset, document.Id),
"collection_ns", encodeNamespace(collectionNamespace),
"collection", collectionName,
"subset", collectionSubset,
Expand Down

0 comments on commit 212c94c

Please sign in to comment.