Skip to content

Commit

Permalink
fix: correctly return reposts from redis
Browse files Browse the repository at this point in the history
  • Loading branch information
VTGare committed Dec 15, 2024
1 parent 28bf4ef commit 9f09a97
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions repost/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,24 @@ func (rd redisDetector) Find(ctx context.Context, channelID, artworkID string) (
var (
rep Repost
key = fmt.Sprintf("channel:%v:artwork:%v", channelID, artworkID)
ttl time.Duration
)

if err := rd.exists(ctx, key); err != nil {
return nil, err
}

var (
result *redis.StringStringMapCmd
ttl time.Duration
)

_, err := rd.client.Pipelined(ctx, func(pipe redis.Pipeliner) error {
err := pipe.HGetAll(ctx, key).Scan(&rep)
if err != nil {
result = pipe.HGetAll(ctx, key)
if err := result.Err(); err != nil {
return err
}

var err error
ttl, err = pipe.TTL(ctx, key).Result()
if err != nil {
return err
Expand All @@ -67,6 +72,10 @@ func (rd redisDetector) Find(ctx context.Context, channelID, artworkID string) (
return nil, err
}

if err := result.Scan(&rep); err != nil {
return nil, err
}

rep.ExpiresAt = time.Now().Add(ttl)
return &rep, nil
}
Expand Down

0 comments on commit 9f09a97

Please sign in to comment.