From bb07142b5c65a62043fbf9c1e65dabd71c57cd51 Mon Sep 17 00:00:00 2001 From: zhenghaoz Date: Sat, 2 Nov 2024 03:09:53 +0800 Subject: [PATCH] ci: fix integrate test (#880) --- client/client_test.go | 4 +++- go.mod | 2 +- go.sum | 4 ++-- storage/cache/redis.go | 47 ++++++++++++++++-------------------------- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/client/client_test.go b/client/client_test.go index f6fa0da3e..17b055fad 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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, diff --git a/go.mod b/go.mod index 1e17dc235..d03af06a5 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,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 diff --git a/go.sum b/go.sum index 2fccce003..49488f278 100644 --- a/go.sum +++ b/go.sum @@ -532,8 +532,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= diff --git a/storage/cache/redis.go b/storage/cache/redis.go index c8510ebe4..b2662e22a 100644 --- a/storage/cache/redis.go +++ b/storage/cache/redis.go @@ -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) } @@ -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,