shop-example/pkg/redistab/redis_key_test.go
2023-08-15 11:22:48 +08:00

29 lines
526 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}