Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTL duration overflow #3031

Open
tkrause opened this issue Jun 18, 2024 · 0 comments
Open

TTL duration overflow #3031

tkrause opened this issue Jun 18, 2024 · 0 comments

Comments

@tkrause
Copy link

tkrause commented Jun 18, 2024

Issue tracker is used for reporting bugs and discussing new features. Please use
stackoverflow for supporting issues.

Expected Behavior

That retrieving a TTL for a key should return a positive value.

Current Behavior

When retrieving a TTL for key with a long duration, time.Duration overflows. For example, set a key in Redis with a TTL of 116637714045176. This library effectively executes the following:

import (
	"fmt"
	"time"
)

func main() {
	i := 116637714045176
	fmt.Println(time.Second * time.Duration(i))
}

The result will be -291314h41m29.494867968s which is no where near correct as it should be 32399365012.54889 hours.

This was discovered when writing a background scan job with this library to remove TTLs that were set incorrectly previously. Because of the overflow, these longer TTL values are not represented correctly but valid in Redis.

Possible Solution

The use of time.Duration should likely be replaced with int64 instead to properly match up with Redis as the time.Duration time is in nanoseconds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant