From 53daf77e1ae625800a786655b898bdcb7aeaa9d0 Mon Sep 17 00:00:00 2001 From: andy-stark-redis <164213578+andy-stark-redis@users.noreply.github.com> Date: Fri, 28 Mar 2025 21:05:36 +0000 Subject: [PATCH 1/3] DOC-4464 examples for llen, lpop, lpush, lrange, rpop, and rpush (#3234) * DOC-4464 examples for llen, lpop, lpush, lrange, rpop, and rpush * DOC-4464 improved variable names --------- Co-authored-by: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Co-authored-by: Nedyalko Dyakov --- doctests/cmds_list_test.go | 323 +++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 doctests/cmds_list_test.go diff --git a/doctests/cmds_list_test.go b/doctests/cmds_list_test.go new file mode 100644 index 00000000..ee4a40a0 --- /dev/null +++ b/doctests/cmds_list_test.go @@ -0,0 +1,323 @@ +// EXAMPLE: cmds_list +// HIDE_START +package example_commands_test + +import ( + "context" + "fmt" + + "github.com/redis/go-redis/v9" +) + +// HIDE_END + +func ExampleClient_cmd_llen() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + rdb.Del(ctx, "mylist") + // REMOVE_END + + // STEP_START llen + lPushResult1, err := rdb.LPush(ctx, "mylist", "World").Result() + + if err != nil { + panic(err) + } + + fmt.Println(lPushResult1) // >>> 1 + + lPushResult2, err := rdb.LPush(ctx, "mylist", "Hello").Result() + + if err != nil { + panic(err) + } + + fmt.Println(lPushResult2) // >>> 2 + + lLenResult, err := rdb.LLen(ctx, "mylist").Result() + + if err != nil { + panic(err) + } + + fmt.Println(lLenResult) // >>> 2 + // STEP_END + + // Output: + // 1 + // 2 + // 2 +} +func ExampleClient_cmd_lpop() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + rdb.Del(ctx, "mylist") + // REMOVE_END + + // STEP_START lpop + RPushResult, err := rdb.RPush(ctx, + "mylist", "one", "two", "three", "four", "five", + ).Result() + + if err != nil { + panic(err) + } + + fmt.Println(RPushResult) // >>> 5 + + lPopResult, err := rdb.LPop(ctx, "mylist").Result() + + if err != nil { + panic(err) + } + + fmt.Println(lPopResult) // >>> one + + lPopCountResult, err := rdb.LPopCount(ctx, "mylist", 2).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lPopCountResult) // >>> [two three] + + lRangeResult, err := rdb.LRange(ctx, "mylist", 0, -1).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lRangeResult) // >>> [four five] + // STEP_END + + // Output: + // 5 + // one + // [two three] + // [four five] +} + +func ExampleClient_cmd_lpush() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + rdb.Del(ctx, "mylist") + // REMOVE_END + + // STEP_START lpush + lPushResult1, err := rdb.LPush(ctx, "mylist", "World").Result() + + if err != nil { + panic(err) + } + + fmt.Println(lPushResult1) // >>> 1 + + lPushResult2, err := rdb.LPush(ctx, "mylist", "Hello").Result() + + if err != nil { + panic(err) + } + + fmt.Println(lPushResult2) // >>> 2 + + lRangeResult, err := rdb.LRange(ctx, "mylist", 0, -1).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lRangeResult) // >>> [Hello World] + // STEP_END + + // Output: + // 1 + // 2 + // [Hello World] +} + +func ExampleClient_cmd_lrange() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + rdb.Del(ctx, "mylist") + // REMOVE_END + + // STEP_START lrange + RPushResult, err := rdb.RPush(ctx, "mylist", + "one", "two", "three", + ).Result() + + if err != nil { + panic(err) + } + + fmt.Println(RPushResult) // >>> 3 + + lRangeResult1, err := rdb.LRange(ctx, "mylist", 0, 0).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lRangeResult1) // >>> [one] + + lRangeResult2, err := rdb.LRange(ctx, "mylist", -3, 2).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lRangeResult2) // >>> [one two three] + + lRangeResult3, err := rdb.LRange(ctx, "mylist", -100, 100).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lRangeResult3) // >>> [one two three] + + lRangeResult4, err := rdb.LRange(ctx, "mylist", 5, 10).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lRangeResult4) // >>> [] + // STEP_END + + // Output: + // 3 + // [one] + // [one two three] + // [one two three] + // [] +} + +func ExampleClient_cmd_rpop() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + rdb.Del(ctx, "mylist") + // REMOVE_END + + // STEP_START rpop + rPushResult, err := rdb.RPush(ctx, "mylist", + "one", "two", "three", "four", "five", + ).Result() + + if err != nil { + panic(err) + } + + fmt.Println(rPushResult) // >>> 5 + + rPopResult, err := rdb.RPop(ctx, "mylist").Result() + + if err != nil { + panic(err) + } + + fmt.Println(rPopResult) // >>> five + + rPopCountResult, err := rdb.RPopCount(ctx, "mylist", 2).Result() + + if err != nil { + panic(err) + } + + fmt.Println(rPopCountResult) // >>> [four three] + + lRangeResult, err := rdb.LRange(ctx, "mylist", 0, -1).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lRangeResult) // >>> [one two] + // STEP_END + + // Output: + // 5 + // five + // [four three] + // [one two] +} + +func ExampleClient_cmd_rpush() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + + // REMOVE_START + rdb.Del(ctx, "mylist") + // REMOVE_END + + // STEP_START rpush + rPushResult1, err := rdb.RPush(ctx, "mylist", "Hello").Result() + + if err != nil { + panic(err) + } + + fmt.Println(rPushResult1) // >>> 1 + + rPushResult2, err := rdb.RPush(ctx, "mylist", "World").Result() + + if err != nil { + panic(err) + } + + fmt.Println(rPushResult2) // >>> 2 + + lRangeResult, err := rdb.LRange(ctx, "mylist", 0, -1).Result() + + if err != nil { + panic(err) + } + + fmt.Println(lRangeResult) // >>> [Hello World] + // STEP_END + + // Output: + // 1 + // 2 + // [Hello World] +} From 0cfcd1a61de06e00798b50ae3571e876e11bdede Mon Sep 17 00:00:00 2001 From: Liu Shuang Date: Thu, 3 Apr 2025 21:10:31 +0800 Subject: [PATCH 2/3] update pubsub.go (#3329) --- pubsub.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubsub.go b/pubsub.go index 72b18f49..20c085f1 100644 --- a/pubsub.go +++ b/pubsub.go @@ -432,7 +432,7 @@ func (c *PubSub) ReceiveTimeout(ctx context.Context, timeout time.Duration) (int return nil, err } - err = cn.WithReader(context.Background(), timeout, func(rd *proto.Reader) error { + err = cn.WithReader(ctx, timeout, func(rd *proto.Reader) error { return c.cmd.readReply(rd) }) From 0df0f3c88785aa16c996089b68b731a4e4a2fdc0 Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Thu, 3 Apr 2025 16:10:51 +0300 Subject: [PATCH 3/3] use 8.0-RC1 (#3330) --- .github/actions/run-tests/action.yml | 2 +- .github/workflows/build.yml | 6 +++--- search_test.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/actions/run-tests/action.yml b/.github/actions/run-tests/action.yml index def48baf..2edb16d3 100644 --- a/.github/actions/run-tests/action.yml +++ b/.github/actions/run-tests/action.yml @@ -25,7 +25,7 @@ runs: # Mapping of redis version to redis testing containers declare -A redis_version_mapping=( - ["8.0-M05"]="8.0-M05-pre" + ["8.0-RC1"]="8.0-RC1-pre" ["7.4.2"]="rs-7.4.0-v2" ["7.2.7"]="rs-7.2.0-v14" ) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 48bbdb75..f88ca672 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: redis-version: - - "8.0-M05" # 8.0 milestone 5 + - "8.0-RC1" # 8.0 RC1 - "7.4.2" # should use redis stack 7.4 go-version: - "1.23.x" @@ -43,7 +43,7 @@ jobs: # Mapping of redis version to redis testing containers declare -A redis_version_mapping=( - ["8.0-M05"]="8.0-M05-pre" + ["8.0-RC1"]="8.0-RC1-pre" ["7.4.2"]="rs-7.4.0-v2" ) if [[ -v redis_version_mapping[$REDIS_VERSION] ]]; then @@ -72,7 +72,7 @@ jobs: fail-fast: false matrix: redis-version: - - "8.0-M05" # 8.0 milestone 5 + - "8.0-RC1" # 8.0 RC1 - "7.4.2" # should use redis stack 7.4 - "7.2.7" # should redis stack 7.2 go-version: diff --git a/search_test.go b/search_test.go index 296f5bd8..4359b02f 100644 --- a/search_test.go +++ b/search_test.go @@ -381,7 +381,7 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() { // up until redis 8 the default scorer was TFIDF, in redis 8 it is BM25 // this test expect redis major version >= 8 It("should FTSearch WithScores", Label("search", "ftsearch"), func() { - SkipBeforeRedisVersion(7.9, "default scorer is not BM25") + SkipBeforeRedisVersion(7.9, "default scorer is not BM25STD") text1 := &redis.FieldSchema{FieldName: "description", FieldType: redis.SearchFieldTypeText} val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, text1).Result()