Skip to content

Rely on TTL timer to define wether or not start expiration window#3

Merged
ryakh merged 1 commit intomasterfrom
measure-expiration-window-against-ttl
Aug 31, 2020
Merged

Rely on TTL timer to define wether or not start expiration window#3
ryakh merged 1 commit intomasterfrom
measure-expiration-window-against-ttl

Conversation

@ryakh
Copy link
Copy Markdown
Collaborator

@ryakh ryakh commented Aug 31, 2020

.expire command on redis will return false if performed on top of a key that does not exist and true if key exists. .ttl on other hand returns -1 if key has no expiration and -2 if key does not exist.

So this seems to be like a safe choice to go with so we can make rate limiting self-healing in case something taints the key.

@ryakh ryakh requested a review from rydama August 31, 2020 09:55

def start_expiration_window
return if current_requests.zero?
return if current_ttl.zero?
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your description of the ttl returns values made sense to me... so I don't understand why this checks for current_ttl.zero? instead of current_ttl.negative? Maybe this strategy is different somehow?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah nice catch! It was just me being stupid, fixed that

Copy link
Copy Markdown

@rydama rydama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it should fix the issue I'm seeing 👍

Just one question about the use of current_ttl.zero? in the sliding window strategy.

@ryakh ryakh force-pushed the measure-expiration-window-against-ttl branch from c161409 to 1c7a79c Compare August 31, 2020 14:04
@ryakh ryakh merged commit 0c435f4 into master Aug 31, 2020
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

Successfully merging this pull request may close these issues.

2 participants