save code

This commit is contained in:
白茶清欢 2024-06-25 19:39:49 +08:00
parent 943d5f36cb
commit 0eeb2ef42e
3 changed files with 23 additions and 5 deletions

View File

@ -8,7 +8,8 @@
package define
const (
DefaultPartitionNum = 1
DefaultRedisPartitionNum = 1
DefaultRedisTopic = "EVENT_TOPIC_C6DBE0AAE846C5C0DE35802107326B1E"
)
// RedisEventPubSubConfig redis事件配置

View File

@ -11,7 +11,6 @@ import (
"context"
"git.zhangdeman.cn/zhangdeman/event/abstract"
"git.zhangdeman.cn/zhangdeman/event/define"
"git.zhangdeman.cn/zhangdeman/wrapper"
"github.com/redis/go-redis/v9"
)
@ -41,7 +40,6 @@ func InitRedisPubSubEvent(redisClient *redis.Client, pubSubConfig *define.RedisE
type RedisEventPubSub struct {
redisClient *redis.Client // redis客户端
pubSubConfig *define.RedisEventPubSubConfig // 事件配置
}
func (r *RedisEventPubSub) SendEvent(ctx context.Context, eventData *define.EventData) (*define.SendResult, error) {
@ -102,10 +100,10 @@ func (r *RedisEventPubSub) SetRedisClient(redisClient *redis.Client, pubSubConfi
}
}
if len(pubSubConfig.Topic) == 0 {
pubSubConfig.Topic = "EVENT_TOPIC_" + wrapper.StringFromRandom(128, "").Md5().Value
pubSubConfig.Topic = define.DefaultRedisTopic
}
if pubSubConfig.PartitionNum <= 0 {
pubSubConfig.PartitionNum = define.DefaultPartitionNum
pubSubConfig.PartitionNum = define.DefaultRedisPartitionNum
}
r.redisClient = redisClient
r.pubSubConfig = pubSubConfig

19
redis_pub_sub_test.go Normal file
View File

@ -0,0 +1,19 @@
// Package event ...
//
// Description : event ...
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2024-06-25 16:51
package event
import (
"fmt"
"git.zhangdeman.cn/zhangdeman/wrapper"
"strings"
"testing"
)
func TestInitRedisPubSubEvent(t *testing.T) {
fmt.Println(strings.ToUpper(wrapper.StringFromRandom(128, "").Md5().Value))
}