upgrade: update wrapper

This commit is contained in:
2025-10-13 22:56:21 +08:00
parent 75567b4088
commit 89c7e205de
4 changed files with 41 additions and 17 deletions

View File

@ -11,13 +11,15 @@ import (
"context"
"errors"
"fmt"
"time"
"git.zhangdeman.cn/zhangdeman/consts"
"git.zhangdeman.cn/zhangdeman/event/abstract"
"git.zhangdeman.cn/zhangdeman/event/define"
"git.zhangdeman.cn/zhangdeman/serialize"
"git.zhangdeman.cn/zhangdeman/wrapper"
"git.zhangdeman.cn/zhangdeman/wrapper/op_string"
"git.zhangdeman.cn/zhangdeman/wrapper/op_ternary"
"github.com/redis/go-redis/v9"
"time"
)
var (
@ -64,7 +66,7 @@ type RedisEventPubSub struct {
//
// Date : 10:58 2024/6/27
func (r *RedisEventPubSub) SendEvent(ctx context.Context, eventData *define.EventData) (*define.SendResult, error) {
partition := int(wrapper.String(eventData.Key).HashNumber().Value % uint64(r.pubSubConfig.PartitionNum))
partition := int(op_string.HashNumber(eventData.Key).Value % uint64(r.pubSubConfig.PartitionNum))
realTopic := fmt.Sprintf("%v_%v", r.pubSubConfig.Topic, partition)
res := r.redisClient.Publish(ctx, realTopic, eventData)
if nil == res {
@ -75,7 +77,7 @@ func (r *RedisEventPubSub) SendEvent(ctx context.Context, eventData *define.Even
Partition: partition,
Topic: realTopic,
IsSuccess: res.Err() == nil,
FailReason: wrapper.TernaryOperator.String(res.Err() == nil, "success", wrapper.String(res.Err().Error())).Value(),
FailReason: op_ternary.BaseType[string](res.Err() == nil, "success", res.Err().Error()),
Extension: nil,
}, res.Err()
}