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

feat: [GH-203] Add support for PXAT in SET command #237

Conversation

lucifercr07
Copy link
Contributor

@lucifercr07 lucifercr07 commented Aug 4, 2024

Change Details:

  • Added support for PXAT in SET command similar to the PXAT option in Redis.
  • Format: SET key val PXAT unix-time-milliseconds
  • Added unit and integration test for the same.
  • Currently there's no mechanism to handle immediate expiration for past PXAT timestamps. Hence added setExpiry to be set to 0 ms when creating NewObj.

Test scenarios:

  • Invalid values for PXAT e.g: str, -ve int etc.
  • Expiry of keys associated with valid UNIX ms
  • Expiry of keys associated with invalid UNIX ms
image


exDurationUnixMs, err := strconv.ParseInt(args[i], 10, 64)
if err != nil {
return Encode(errors.New("ERR value is not an integer or out of range"), false)
Copy link
Contributor

@soumya-codes soumya-codes Aug 4, 2024

Choose a reason for hiding this comment

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

Not a requirement for this PR, but it may be a good time to start consolidating/reusing the error messages for easier maintainability and ensuring that the error messages are exactly as that of REDIS.

@arpitbbhayani @JyotinderSingh if you guys feel there is a need i can open a PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@soumya-codes please let me know I can create an issue and work on this if required.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can create the task for tracking purposes. Let's wait for Arpit and Jyotinder to see if this task needs to prioritized now over adding newer features. I am new to the project and I not aware of the current priorities.

Copy link
Contributor

Choose a reason for hiding this comment

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

@soumya-codes Good point. We should start consolidating error messages. High time :)

Copy link
Contributor

@soumya-codes soumya-codes left a comment

Choose a reason for hiding this comment

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

@lucifercr07 the changes look good and the test cases are exhaustive. I have left a couple of comments. Please let me know what you think about the same.


exDurationMs = exDurationUnixMs - time.Now().UnixMilli()
// If the expiry time is in the past, set exDurationMs to 0
// This will be used to signal immediate expiration
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Instead of creating a new object with expiry time set to zero, should we delete the key instead? How is it handled in Redis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Redis does not reject the key, instead it sets the key and immediately expires it if the timestamp has already passed.

@@ -45,7 +45,7 @@ func NewObj(value interface{}, expDurationMs int64, oType uint8, oEnc uint8) *Ob
TypeEncoding: oType | oEnc,
LastAccessedAt: getCurrentClock(),
}
if expDurationMs > 0 {
if expDurationMs >= 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

yes. that is a good catch.

@arpitbbhayani arpitbbhayani merged commit f4b56e5 into DiceDB:master Aug 4, 2024
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.

3 participants