Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
githubzhaoqian committed Sep 2, 2024
1 parent 842fed1 commit d62c971
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 4 additions & 5 deletions pkg/rediszset/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,16 @@ func (p *Publisher) Publish(topic string, msgs ...*message.Message) error {
if err != nil {
return errors.Wrapf(err, "cannot marshal message %s", msg.UUID)
}

id, err := p.client.ZAdd(msg.Context(), topic, redis.Z{Score: score, Member: msg.UUID}).Result()
if err != nil {
return errors.Wrapf(err, "cannot zadd message %s", msg.UUID)
}
// 设置string 值
valueKey := getKey(topic, msg.UUID)
_, err = p.client.Set(msg.Context(), valueKey, value, 0).Result()
if err != nil {
return errors.Wrapf(err, "cannot set message %s", msg.UUID)
}
id, err := p.client.ZAdd(msg.Context(), topic, redis.Z{Score: score, Member: msg.UUID}).Result()
if err != nil {
return errors.Wrapf(err, "cannot zadd message %s", msg.UUID)
}
logFields["zadd_id"] = id
p.logger.Trace("Message sent to redis stream", logFields)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/rediszset/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ func (h *messageHandler) processMessage(ctx context.Context, topic string, read
src := read.Z.Member.(string)
srcKey := getKey(topic, src)
member, err := h.rc.Get(ctx, srcKey).Result()
if errors.Is(err, redis.Nil) {
h.logger.Error("Message nil", err, watermill.LogFields{"key": srcKey})
return nil
}
if err != nil {
return errors.Wrapf(err, "message %s get failed", srcKey)
}
Expand Down

0 comments on commit d62c971

Please sign in to comment.