diff --git a/define/redis.go b/define/redis.go index 63755e4..5892399 100644 --- a/define/redis.go +++ b/define/redis.go @@ -8,7 +8,8 @@ package define const ( - DefaultPartitionNum = 1 + DefaultRedisPartitionNum = 1 + DefaultRedisTopic = "EVENT_TOPIC_C6DBE0AAE846C5C0DE35802107326B1E" ) // RedisEventPubSubConfig redis事件配置 diff --git a/redis_pub_sub.go b/redis_pub_sub.go index 0956c35..6db7505 100644 --- a/redis_pub_sub.go +++ b/redis_pub_sub.go @@ -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 diff --git a/redis_pub_sub_test.go b/redis_pub_sub_test.go new file mode 100644 index 0000000..2c044d5 --- /dev/null +++ b/redis_pub_sub_test.go @@ -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)) +}