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

Implement CAS and CAD commands for string type #415

Merged
merged 1 commit into from
Dec 3, 2021

Conversation

caipengbo
Copy link
Contributor

CAS

This command can be used to atomic change the value of a specified key to a new value if the current value of the key matches a specified value. The value is not changed if the current value of the key does not match the specified value.

Syntax:

CAS key old_value new_value [EX seconds | PX milliseconds]

Parameters:

Parameters Description
key The key of the string that you want to manage with CAS command
old_value The value that you compare with the current value of the specified key
new_value Changes the value of the specified key to the value of this parameter if the current value of the key matches the specified value
EX or PX Expiration time, it has the same meaning as the SET command

Returned values:

  • 1: the operation is successful
  • -1: the specified key does not exist
  • 0: the operation fails
  • Otherwise, an error message is returned.

CAD

This command can be used to atomic delete a specified key if the current value of the key matches a specified value. The key is not deleted if the current value of the key does not match the specified value.

Syntax:

CAD key value

Parameters:

Parameters Description
key The key of the Redis string that you want to manage with CAD command
value The value that you compare with the current value of the specified key

Returned values:

  • 1: the operation is successful
  • -1: the specified key does not exist
  • 0: the operation fails
  • Otherwise, an error message is returned

@caipengbo caipengbo requested review from git-hulk and ShooterIT and removed request for git-hulk December 3, 2021 07:03
@ShooterIT
Copy link
Member

lgtm, cool job!

After merging this PR, i think we should support EXAT PXAT options for SET and CAS, since these options are frequently-used and friendly, WDYT? @caipengbo @git-hulk

@caipengbo
Copy link
Contributor Author

After merging this PR, i think we should support EXAT PXAT options for SET and CAS, since these options are frequently-used and friendly, WDYT?

Yeah, we should be as compliant with Redis commands as possible.

@ShooterIT
Copy link
Member

@caipengbo Could update our wiki https://github.com/KvrocksLabs/kvrocks/wiki/Support-Commands for these new commands

@caipengbo
Copy link
Contributor Author

I want to update the wiki, but I don't have permission @ShooterIT

@ShooterIT ShooterIT changed the title Add CAS and CAD support for string type Support CAS and CAD commands for string type Dec 3, 2021
@ShooterIT ShooterIT linked an issue Dec 3, 2021 that may be closed by this pull request
@ShooterIT
Copy link
Member

oh, let me update

@ShooterIT ShooterIT changed the title Support CAS and CAD commands for string type Implement CAS and CAD commands for string type Dec 3, 2021
@ShooterIT ShooterIT merged commit 1c021ae into apache:unstable Dec 3, 2021
@caipengbo caipengbo deleted the support-cas-cad branch December 3, 2021 12:38
ShooterIT pushed a commit to ShooterIT/kvrocks that referenced this pull request Dec 7, 2021
CAS, set its value to new value when the current value of the string corresponding to key is equal to old value.
- syntax: CAS key old_value new_value [EX seconds | PX milliseconds]
- return value: returns 1 if the value is successfully updated, -1 if the key does not exist, and 0 if the value fails to be updated

CAD, delete the key when the value is equal to the value in the db.
- syntax: CAD key value
- return value: returns 1 if the value is successfully updated, -1 if the key does not exist, and 0 if the value fails to be updated

More details, please see apache#415
@ShooterIT ShooterIT mentioned this pull request Dec 7, 2021
ShooterIT pushed a commit that referenced this pull request Dec 7, 2021
CAS, set its value to new value when the current value of the string corresponding to key is equal to old value.
- syntax: CAS key old_value new_value [EX seconds | PX milliseconds]
- return value: returns 1 if the value is successfully updated, -1 if the key does not exist, and 0 if the value fails to be updated

CAD, delete the key when the value is equal to the value in the db.
- syntax: CAD key value
- return value: returns 1 if the value is successfully updated, -1 if the key does not exist, and 0 if the value fails to be updated

More details, please see #415
enjoy-binbin added a commit to enjoy-binbin/kvrocks that referenced this pull request Aug 7, 2023
Since we have already implemented these options
in SET / GETEX, the change is very simple.

Some ref links:
- CAS was added in apache#415
- SET EXAP / PXAT options was added in apache#901
- GETEX was added in apache#961
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NEW] Support CAS/CAD commands
3 participants