-
Notifications
You must be signed in to change notification settings - Fork 24.4k
GETEX, GETDEL and SET PXAT/EXAT #8327
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
Conversation
|
@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. |
oranagra
left a comment
There was a problem hiding this 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.
|
IMHO |
|
@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. 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. |
oranagra
left a comment
There was a problem hiding this 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:
- making sure GETEX with no arguments isn't propagated
- use of PERSIST
- EX/PX/EXAT/PXAT
- DEL
…#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.
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.
|
@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. |
oranagra
left a comment
There was a problem hiding this 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.
|
Okay the long version then :)
|
Update the PR.
Propagate as UNLINK
|
Ok, next. Who wants to make a redis-doc PR? |
|
@oranagra I will follow up with a doc soon. |
Documentation changes corresponding to redis/redis#8327.
Documentation changes corresponding to PR redis/redis#8327.
Documentation changes corresponding to PR redis/redis#8327.
|
Document PR - redis/redis-doc#1501 |
Documentation changes corresponding to PR redis/redis#8327.
…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.
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
This commit introduces two new command and two options for an existing command
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.
Command would return either the bulk string, error or nil.
Would delete the key after getting.
Two new options added here are EXAT and PXAT
Key implementation notes
SETwithPX/EX/EXAT/PXATis always translated toPXATinAOF. When relative time is specified (PX/EX), replication will always usePX.setexCommandandpsetexCommandwould no longer need translation infeedAppendOnlyFileas they are modified to invokesetGenericCommandwith appropriate flags which will take care of correct AOF translation.GETEXwithout any optional argument behaves likeGET.GETEXcommand is never propagated, It is either propagated asPEXPIRE[AT], or PERSIST.GETDELcommand is propagated asDELSETandGETEXarguments.Issue - #2762