Skip to content

Conversation

@ndyakov
Copy link
Member

@ndyakov ndyakov commented Nov 5, 2025

Adding CAS/CAD commands available in redis 8.4:

SET key value [NX | XX
  | IFEQ match-value | IFNE match-value
  | IFDEQ match-digest | IFDNE match-digest] [GET]
# return changes:
# - if GET specified, returns previous value (regardless of IFEQ etc)
# - if GET not specified, nil reply if operation aborted due to IFEQ etc
DELEX key [IFEQ match-value | IFNE match-value
  | IFDEQ match-digest | IFDNE match-digest]
# returns integer of the number of keys that were removed (so: 0 or 1)
DIGEST key
# returns hex of the specified key (pending "null if not exists?")

I did change the methods and added *Get methods for each SetIF* method, since the responses mean different things (i.e. Set will return status OK but if it is set ... ifneq .. get it still can return OK if the previous value of the key was OK. This way it is more clear, the returned commands are StatusCmd or StringCmd and they both mean different things (should) to the user.
What is still a StatusCmd that can actually hold the previous value, is the return of SetArgs if we have Get=True in the args. Any feedback on how to handle this better is welcome.

@ndyakov ndyakov changed the title add cas/cad commands feat: Add CAS/CAD commands Nov 5, 2025
@ndyakov ndyakov changed the title feat: Add CAS/CAD commands feat(cmd): Add CAS/CAD commands Nov 5, 2025
ndyakov and others added 6 commits November 5, 2025 16:32
Decided to move the *Get argument as a separate methods, since the
response will be always the previous value, but in the case where
the previous value is `OK` there result may be ambiguous.
@ndyakov
Copy link
Member Author

ndyakov commented Nov 6, 2025

I am considering changing the digest to uint64 to match https://github.com/zeebo/xxh3 and add documentation to suggest using https://github.com/zeebo/xxh3 for generating digests on the application level.

@ndyakov ndyakov force-pushed the ndyakov/CAE-1672-cas-cad branch from 6af5087 to bdefae8 Compare November 6, 2025 22:21
@ndyakov ndyakov force-pushed the ndyakov/CAE-1672-cas-cad branch from bdefae8 to 3a31338 Compare November 6, 2025 22:47
Copy link
Collaborator

@ofekshenawa ofekshenawa left a comment

Choose a reason for hiding this comment

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

LGTM!

@ndyakov ndyakov merged commit 5069fd6 into master Nov 7, 2025
22 checks passed
@ndyakov ndyakov deleted the ndyakov/CAE-1672-cas-cad branch November 7, 2025 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants