Skip to content

Conversation

@nmvk
Copy link
Contributor

@nmvk nmvk commented Jan 13, 2021

This commit introduces two new command and two options for an existing command

GETEX <key> [PERSIST][EX seconds][PX milliseconds] [EXAT seconds-timestamp][PXAT milliseconds-timestamp]

The getexCommand() function implements extended options and variants of the GET command. Unlike GET command this command is not read-only. Only one of the options can be used at a given time.

  1. PERSIST removes any TTL associated with the key.
  2. EX Set expiry TTL in seconds.
  3. PX Set expiry TTL in milliseconds.
  4. EXAT Same like EX instead of specifying the number of seconds representing the TTL (time to live), it takes an absolute Unix timestamp
  5. PXAT Same like PX instead of specifying the number of milliseconds representing the TTL (time to live), it takes an absolute Unix timestamp

Command would return either the bulk string, error or nil.

GETDEL <key>

Would delete the key after getting.

SET key value [NX] [XX] [KEEPTTL] [GET] [EX <seconds>] [PX <milliseconds>] [EXAT <seconds-timestamp>][PXAT <milliseconds-timestamp>]

Two new options added here are EXAT and PXAT

Key implementation notes

  • SET with PX/EX/EXAT/PXAT is always translated to PXAT in AOF. When relative time is specified (PX/EX), replication will always use PX.
  • setexCommand and psetexCommand would no longer need translation in feedAppendOnlyFile as they are modified to invoke setGenericCommand with appropriate flags which will take care of correct AOF translation.
  • GETEX without any optional argument behaves like GET.
  • GETEX command is never propagated, It is either propagated as PEXPIRE[AT], or PERSIST.
  • GETDEL command is propagated as DEL
  • Combined the validation for SET and GETEX arguments.
  • Test cases to validate AOF/Replication propagation

Issue - #2762

@madolson madolson added state:major-decision Requires core team consensus state:needs-doc-pr requires a PR to redis-doc repository labels Jan 13, 2021
@madolson madolson linked an issue Jan 13, 2021 that may be closed by this pull request
@madolson madolson removed a link to an issue Jan 13, 2021
@nmvk nmvk requested a review from madolson January 14, 2021 01:28
@madolson madolson linked an issue Jan 18, 2021 that may be closed by this pull request
@madolson madolson added the approval-needed Waiting for core team approval to be merged label Jan 18, 2021
madolson
madolson previously approved these changes Jan 18, 2021
@madolson
Copy link
Contributor

@redis/core-team

Hey, this should be ready for review. I looked through the command code, but would appreciate another pair of eyes at least since that is not the code I'm more comfortable with.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

@nmvk thanks for this PR.
added a few comments that should be trivial to solve.

the only one that would probably require some work is about not propagating absolute expire times to replicas.

@soloestoy
Copy link
Contributor

IMHO MULTI/EXEC and lua script can do it better, but if users really wanna it, I prefer some clear and specific commands like GETEX/PGETEX/GETDEL as mentioned in the original issue, it's not easy to understand and use GETEX with so much flags, especially these flags have many conflict.

@oranagra
Copy link
Member

@soloestoy indeed it can be achieved by MULTI exec, but this will make it more convenient for users, and AFAIK it was requested a lot.

The problem with splitting it to many commands is that whenever we wanna add a new option, we need to add it to all of them, or add another variant of the command.
Redis did abandon SETEX, SETNX, SETXX a long time ago in favor of SET with various arguments.
and we recently abandoned GETSET (to avoid adding an EX argument to it) in favor of SET with GET argument, and did the same to many many other commands (ZRANGE, GEORADIUS*, PUPPUSH).

so as long as the GETEX command is always a write command and always refers to one key, and always returns the value, i think we should stick with one command rather than several.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

i think we must add specific tests for the replication and AOF propagation of all the GETEX variants.
including:

  1. making sure GETEX with no arguments isn't propagated
  2. use of PERSIST
  3. EX/PX/EXAT/PXAT
  4. DEL

oranagra added a commit that referenced this pull request Jan 19, 2021
…#8357)

This commit adds tests to make sure that relative and absolute expire commands
are propagated as is to replicas and stop any future attempt to change that without
a proper discussion. see #8327 and #5171

Additionally it slightly improve the AOF test that tests the opposite (always
propagating absolute times), by covering more commands, and shaving 2
seconds from the test time.
nmvk added 3 commits January 20, 2021 00:42
This commit introduces one new command and two options for an existing command

GETEX <key> [KEEPTTL][PERSIST][DEL][EX seconds][PX milliseconds] [EXAT seconds-timestamp][PXAT milliseconds-timestamp]

The getexCommand() function implements extended options and variants of the GET command. Unlike GET command this command is not read-only. Only one of the options can be used at a given time.

1. KEEPTTL is the default behavior and does not alter any TTL.
2. PERSIST removes any TTL associated with the key.
3. DEL deletes the key after the return.
4. EX Set expiry TTL in seconds.
5. PX Set expiry TTL in milliseconds.
6. EXAT Same like EX instead of specifying the number of seconds representing the TTL (time to live), it takes an absolute Unix timestamp
7. PXAT Same like PX instead of specifying the number of milliseconds representing the TTL (time to live), it takes an absolute Unix timestamp

Command would either return the bulk string, error or nil.

SET key value [NX] [XX] [KEEPTTL] [GET] [EX <seconds>] [PX <milliseconds>] [EXAT <seconds-timestamp>][PXAT <milliseconds-timestamp>]

The two new options added here are EXAT and PXAT
Rewrote the propagation to use relative TTL
when PX/EX is specified.
AOF will transalte the PX to SET with PEXPIREAT.

If PXAT/EXAT time has elapsed in GETEX, performining
delete now.

Changed default behavior of GETEX to be same as GET.

Fixed other PR comments.
Replication and AOF test coverage for different
options of GETEX.

Modified the existing expiration test to include
SET PXAT/EXAT and GETEX.

Added a test to ensure if GETEX is invoked with no
arguments then not to write anything to AOF file.
@oranagra
Copy link
Member

@nmvk please avoid pushing a rebase and an actual change (editing old commits) in the same force-push, it's very hard for me to find your changes and review them.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

minor suggestions for improvements and then i think this is ready to be merged.

Updated comments from PR review.

Updated GETEX PERSIST propagate to
replica test to include DEL case.
@nmvk nmvk requested a review from oranagra January 20, 2021 17:12
@nmvk nmvk requested review from madolson, oranagra and yossigo January 25, 2021 19:33
@nmvk nmvk changed the title GETEX and SET PXAT/EXAT GETEX, GETDEL and SET PXAT/EXAT Jan 25, 2021
@yossigo
Copy link
Collaborator

yossigo commented Jan 25, 2021

Okay the long version then :)

  • GETX seems confusing, creates yet another command notation which I don't think we want at this point.
  • POP implies an operation on a collection, I think it's confusing.
  • TAKE is a bit awkward for me as it doesn't seem related in any way to GET.
  • GETEX is not perfect, it's a bit ambiguous as it is more easy to interpret as "expire" rather than "extended", but I can't come up with something better. At some point I did toy with GETMUT (mutable get) but:
    • It would make more sense if we also give up GETDEL and use a DEL argument, which is not good introspection-wise
    • Is also awkward
    • Steers this discussion further from a conclusion

Update the PR.
@nmvk nmvk requested a review from madolson January 26, 2021 04:44
Propagate as UNLINK
@nmvk nmvk requested a review from madolson January 26, 2021 05:27
@oranagra
Copy link
Member

Ok, next. Who wants to make a redis-doc PR?

@nmvk
Copy link
Contributor Author

nmvk commented Jan 26, 2021

@oranagra I will follow up with a doc soon.

nmvk pushed a commit to nmvk/redis-doc that referenced this pull request Jan 26, 2021
Documentation changes corresponding to
redis/redis#8327.
nmvk added a commit to nmvk/redis-doc that referenced this pull request Jan 26, 2021
Documentation changes corresponding to PR
redis/redis#8327.
nmvk added a commit to nmvk/redis-doc that referenced this pull request Jan 26, 2021
Documentation changes corresponding to PR
redis/redis#8327.
@nmvk
Copy link
Contributor Author

nmvk commented Jan 26, 2021

Document PR - redis/redis-doc#1501

@oranagra oranagra merged commit 0367a80 into redis:unstable Jan 27, 2021
itamarhaber pushed a commit to redis/redis-doc that referenced this pull request Jan 28, 2021
@oranagra oranagra mentioned this pull request Jan 31, 2021
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Mar 2, 2021
…redis#8357)

This commit adds tests to make sure that relative and absolute expire commands
are propagated as is to replicas and stop any future attempt to change that without
a proper discussion. see redis#8327 and redis#5171

Additionally it slightly improve the AOF test that tests the opposite (always
propagating absolute times), by covering more commands, and shaving 2
seconds from the test time.
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Mar 2, 2021
This commit introduces two new command and two options for an existing command

GETEX <key> [PERSIST][EX seconds][PX milliseconds] [EXAT seconds-timestamp]
[PXAT milliseconds-timestamp]

The getexCommand() function implements extended options and variants of the GET
command. Unlike GET command this command is not read-only. Only one of the options
can be used at a given time.

1. PERSIST removes any TTL associated with the key.
2. EX Set expiry TTL in seconds.
3. PX Set expiry TTL in milliseconds.
4. EXAT Same like EX instead of specifying the number of seconds representing the
    TTL (time to live), it takes an absolute Unix timestamp
5. PXAT Same like PX instead of specifying the number of milliseconds representing the
    TTL (time to live), it takes an absolute Unix timestamp

Command would return either the bulk string, error or nil.

GETDEL <key>
Would delete the key after getting.

SET key value [NX] [XX] [KEEPTTL] [GET] [EX <seconds>] [PX <milliseconds>]
[EXAT <seconds-timestamp>][PXAT <milliseconds-timestamp>]

Two new options added here are EXAT and PXAT

Key implementation notes
- `SET` with `PX/EX/EXAT/PXAT` is always translated to `PXAT` in `AOF`. When relative time is
  specified (`PX/EX`), replication will always use `PX`.
- `setexCommand` and `psetexCommand` would no longer need translation in `feedAppendOnlyFile`
  as they are modified to invoke `setGenericCommand ` with appropriate flags which will take care of
  correct AOF translation.
- `GETEX` without any optional argument behaves like `GET`.
- `GETEX` command is never propagated, It is either propagated as `PEXPIRE[AT], or PERSIST`.
- `GETDEL` command is propagated as `DEL`
- Combined the validation for `SET` and `GETEX` arguments. 
- Test cases to validate AOF/Replication propagation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval-needed Waiting for core team approval to be merged state:major-decision Requires core team consensus state:needs-doc-pr requires a PR to redis-doc repository state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature new command GETEX

6 participants