Skip to content

Commit af33a0a

Browse files
authored
Merge pull request #290 from dzbanek717/master
Return true TTL value in rueidis driver
2 parents a31e124 + d215a32 commit af33a0a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

store/rueidis/rueidis.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,23 @@ func (s *RueidisStore) GetWithTTL(ctx context.Context, key any) (any, time.Durat
5656
cmd := s.client.B().Get().Key(key.(string)).Cache()
5757
res := s.client.DoCache(ctx, cmd, s.options.ClientSideCacheExpiration)
5858
str, err := res.ToString()
59+
if rueidis.IsRedisNil(err) {
60+
return res, time.Duration(0), lib_store.NotFoundWithCause(err)
61+
}
62+
63+
ttl, _ := s.GetTTL(ctx, key)
64+
return str, ttl, err
65+
}
66+
67+
func (s *RueidisStore) GetTTL(ctx context.Context, key any) (time.Duration, error) {
68+
cmd := s.client.B().Ttl().Key(key.(string)).Cache()
69+
res := s.client.DoCache(ctx, cmd, s.options.ClientSideCacheExpiration)
70+
castResult, err := res.ToInt64()
5971
if rueidis.IsRedisNil(err) {
6072
err = lib_store.NotFoundWithCause(err)
6173
}
62-
return str, time.Duration(res.CacheTTL()) * time.Second, err
74+
75+
return time.Duration(castResult) * time.Second, err
6376
}
6477

6578
// Set defines data in Redis for given key identifier

0 commit comments

Comments
 (0)