66 lines
2.1 KiB
Go
66 lines
2.1 KiB
Go
package redis
|
||
|
||
import (
|
||
"fmt"
|
||
"log"
|
||
"testing"
|
||
|
||
"qoobing.com/gomod/redis/sentinel"
|
||
"qoobing.com/gomod/redis/xstream"
|
||
)
|
||
|
||
func TestNewConsumer(t *testing.T) {
|
||
cfg := xstream.Config{
|
||
Group: "group_a",
|
||
Stream: "testxstream_queue",
|
||
Sentinel: sentinel.Config{
|
||
Debug: true, //调试开关(会在日志打印REDIS语句)
|
||
MasterName: "walletmaster", //REDIS主名称(一个哨兵集群可管理多个REDIS主从结构)
|
||
Username: "web3wallet", //REDIS连接用户名
|
||
Password: "web3onthemoon@2023#dev", //REDIS连接用户密码
|
||
Sentinels: "sentinel-0.redis:5000", //哨兵节点列表,逗号分隔,一般配置三个
|
||
SentinelUsername: "sentinel", //哨兵节点连接用户名,不填默认default
|
||
SentinelPassword: "password@mhxzkhl#dev", //哨兵节点连接密码,不填认为集群无密码
|
||
},
|
||
}
|
||
|
||
for i := 0; i < 15; i++ {
|
||
i := i
|
||
name := fmt.Sprintf("name-%d", i)
|
||
t.Run(name, func(t *testing.T) {
|
||
t.Parallel()
|
||
log.Println("name", name)
|
||
if r := xstream.NewReader(cfg); r == nil {
|
||
t.Error("create new reader failed")
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
func TestNewPool(t *testing.T) {
|
||
cfg := Config{
|
||
Debug: true, //调试开关(会在日志打印REDIS语句)
|
||
Master: "redis-0.redis:2379", //REDIS主
|
||
Username: "web3wallet", //REDIS连接用户名
|
||
Password: "web3onthemoon@2023#dev", //REDIS连接用户密码
|
||
Sentinels: "sentinel-0.redis:5000", //哨兵节点列表,逗号分隔,一般配置三个
|
||
SentinelUsername: "sentinel", //哨兵节点连接用户名,不填默认default
|
||
SentinelPassword: "password@mhxzkhl#dev", //哨兵节点连接密码,不填认为集群无密码
|
||
}
|
||
pool := NewPool(cfg)
|
||
if pool == nil {
|
||
t.Errorf("new pool failed")
|
||
}
|
||
rds := pool.Get()
|
||
if rds == nil {
|
||
t.Errorf("get redis failed")
|
||
}
|
||
if ret, err := rds.Do("SET", "ABC", "123"); err != nil {
|
||
t.Errorf("get redis failed: %s", err)
|
||
} else {
|
||
fmt.Println("ABC", ret)
|
||
}
|
||
fmt.Println(rds.Do("GET", "ABC"))
|
||
|
||
}
|