Skip to content

Commit 319debf

Browse files
committed
redcache: support millisecond precision
1 parent fbddb10 commit 319debf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

redcache/cache.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ func (c *Cache[V]) Do(
5757
return v, fmt.Errorf("marshal value: %w", err)
5858
}
5959

60-
r = c.Client.Pipeline(ctx, r, "SETEX", fullKey, c.TTL.Seconds(), b)
60+
exp := c.TTL / time.Millisecond
61+
62+
if exp == 0 {
63+
return v, fmt.Errorf("TTL is %v, but must be > %v", c.TTL, time.Millisecond)
64+
}
65+
66+
r = c.Client.Pipeline(ctx, r, "SET", fullKey, b, "PX", int(exp))
6167
err = r.Ok()
6268
if err != nil {
6369
return v, fmt.Errorf("cache set: %w", err)

0 commit comments

Comments
 (0)