valkey-io / valkey

A flexible distributed key-value datastore that is optimized for caching and other realtime workloads.
https://valkey.io
Other
17.36k stars 656 forks source link

Set Command with IFEQ Support #1324

Open sarthakaggarwal97 opened 3 days ago

sarthakaggarwal97 commented 3 days ago

This PR allows the Valkey users to perform conditional updates where the SET command is completed if the given comparison-value matches the key’s current value.

Behavior with this PR

SET <key> <value> IFEQ <comparison-value>

If the values match, the SET completes as expected. If they do not match, the command returns a (nil).

Behavior with Additional Flags

  1. SET <key> <value> IFEQ <comparison-value> GET returns the existing value if present, (nil) if not and gives the error if there is a Type Mismatch. Conditional set operation is performed if the given comparison value matches the existing value.
  2. SET <key> <value> IFEQ <comparison-value> XX returns nil if the key doesn't exist, otherwise conditionally updates the key if the given comparison value matches the existing value.
  3. SET <key> <value> IFEQ <comparison-value> NX returns nil whether or not the key exists. Does not conditionally update the key if NX flag is present

Addresses: #1215

codecov[bot] commented 3 days ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 70.76%. Comparing base (4986310) to head (3dc3407).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## unstable #1324 +/- ## ============================================ + Coverage 70.68% 70.76% +0.07% ============================================ Files 115 115 Lines 63177 63198 +21 ============================================ + Hits 44657 44722 +65 + Misses 18520 18476 -44 ``` | [Files with missing lines](https://app.codecov.io/gh/valkey-io/valkey/pull/1324?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valkey-io) | Coverage Δ | | |---|---|---| | [src/commands.def](https://app.codecov.io/gh/valkey-io/valkey/pull/1324?src=pr&el=tree&filepath=src%2Fcommands.def&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valkey-io#diff-c3JjL2NvbW1hbmRzLmRlZg==) | `100.00% <ø> (ø)` | | | [src/t\_string.c](https://app.codecov.io/gh/valkey-io/valkey/pull/1324?src=pr&el=tree&filepath=src%2Ft_string.c&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valkey-io#diff-c3JjL3Rfc3RyaW5nLmM=) | `96.88% <100.00%> (+0.13%)` | :arrow_up: | ... and [18 files with indirect coverage changes](https://app.codecov.io/gh/valkey-io/valkey/pull/1324/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valkey-io)

🚨 Try these New Features:

hpatro commented 2 days ago

@sarthakaggarwal97 Please avoid force pushing. force push removes the reviewer's history in Github and one needs to look at the entire change again.

sarthakaggarwal97 commented 2 days ago

noted @hpatro, will avoid it.