1
0
mirror of https://github.com/redis/go-redis.git synced 2025-12-03 18:31:14 +03:00
Files
go-redis/autopipeline_blocking_test.go
Nedyalko Dyakov b6d7cdbd84 chore(ci): Add redis 8.4-RC1-pre & examples (#3572)
* add disable maintnotifications example

* add 8.4-RC1-pre

* println -> printf for linter

* address jit comment

Fix broken initialization of idle connections

optimize push notif

wip

wip

wip

wip
2025-10-29 13:49:32 +02:00

75 lines
2.0 KiB
Go

package redis_test
import (
"context"
"time"
"github.com/redis/go-redis/v9"
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
)
var _ = Describe("AutoPipeline Blocking Commands", func() {
ctx := context.Background()
var client *redis.Client
var ap *redis.AutoPipeliner
BeforeEach(func() {
client = redis.NewClient(&redis.Options{
Addr: redisAddr,
})
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
ap = client.AutoPipeline()
})
AfterEach(func() {
if ap != nil {
Expect(ap.Close()).NotTo(HaveOccurred())
}
Expect(client.Close()).NotTo(HaveOccurred())
})
It("should not autopipeline blocking commands", func() {
// Push a value to the list
Expect(client.RPush(ctx, "list", "value").Err()).NotTo(HaveOccurred())
// BLPOP should execute immediately without autopipelining
start := time.Now()
result := ap.Do(ctx, "BLPOP", "list", "1")
val, err := result.(*redis.StringSliceCmd).Result()
elapsed := time.Since(start)
Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal([]string{"list", "value"}))
// Should complete quickly since value is available
Expect(elapsed).To(BeNumerically("<", 100*time.Millisecond))
})
It("should mix blocking and non-blocking commands", func() {
// Push values
Expect(client.RPush(ctx, "list3", "a", "b", "c").Err()).NotTo(HaveOccurred())
Expect(client.Set(ctx, "key1", "value1", 0).Err()).NotTo(HaveOccurred())
// Mix blocking and non-blocking commands
blpopCmd := ap.Do(ctx, "BLPOP", "list3", "1")
getCmd := ap.Do(ctx, "GET", "key1")
brpopCmd := ap.Do(ctx, "BRPOP", "list3", "1")
// Get results
blpopVal, err := blpopCmd.(*redis.StringSliceCmd).Result()
Expect(err).NotTo(HaveOccurred())
Expect(blpopVal).To(Equal([]string{"list3", "a"}))
getVal, err := getCmd.(*redis.StringCmd).Result()
Expect(err).NotTo(HaveOccurred())
Expect(getVal).To(Equal("value1"))
brpopVal, err := brpopCmd.(*redis.StringSliceCmd).Result()
Expect(err).NotTo(HaveOccurred())
Expect(brpopVal).To(Equal([]string{"list3", "c"}))
})
})