From 9f09a97be435da742c7863f78e1beb9f86f96dd4 Mon Sep 17 00:00:00 2001 From: VTGare Date: Sun, 15 Dec 2024 21:49:54 +0200 Subject: [PATCH] fix: correctly return reposts from redis --- repost/redis.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/repost/redis.go b/repost/redis.go index 24e161d..d791108 100644 --- a/repost/redis.go +++ b/repost/redis.go @@ -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 @@ -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 }