shop-example/pkg/redistab/redis_key_test.go

29 lines
526 B
Go
Raw Normal View History

2023-08-15 03:22:48 +00:00
package redistab
import (
"fmt"
"testing"
"time"
)
func TestGetProductBitMap(t *testing.T) {
// 创建一个带有缓冲区的channel
ch := make(chan int, 3)
// 启动多个监听者
for i := 1; i <= 3; i++ {
go func(i int) {
// 从channel中读取数据并将其打印到控制台
fmt.Printf("监听器%d收到消息%d\n", i, <-ch)
}(i)
}
// 向channel发送消息
for i := 1; i <= 5; i++ {
ch <- i
}
// 等待所有监听者处理完所有消息
time.Sleep(3*time.Second)
}