Skip to content

Commit aa2aeb3

Browse files
Documentation for SET IFEQ (#189)
This PR adds the documentation to support valkey-io/valkey#1324 --------- Signed-off-by: Sarthak Aggarwal <[email protected]> Signed-off-by: Viktor Söderqvist <[email protected]> Co-authored-by: Viktor Söderqvist <[email protected]>
1 parent d6f2554 commit aa2aeb3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

commands/set.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,40 @@ The `SET` command supports a set of options that modify its behavior:
1212
* `PXAT` *timestamp-milliseconds* -- Set the specified Unix time at which the key will expire, in milliseconds (a positive integer).
1313
* `NX` -- Only set the key if it does not already exist.
1414
* `XX` -- Only set the key if it already exists.
15+
* `IFEQ` *comparison-value* -- Set the key if the comparison value matches the existing value. An error is returned and `SET` aborted if the value stored at key is not a string.
1516
* `KEEPTTL` -- Retain the time to live associated with the key.
16-
* `!GET` -- Return the old string stored at key, or nil if key did not exist. An error is returned and `SET` aborted if the value stored at key is not a string.
17+
* `GET` -- Return the old string stored at key, or nil if key did not exist. An error is returned and `SET` aborted if the value stored at key is not a string.
1718

1819
Note: Since the `SET` command options can replace `SETNX`, `SETEX`, `PSETEX`, `GETSET`, it is possible that in future versions of Valkey these commands will be deprecated and finally removed.
1920

2021
## Examples
2122

23+
Basic usage
2224
```
2325
127.0.0.1:6379> SET mykey "Hello"
2426
OK
2527
127.0.0.1:6379> GET mykey
2628
"Hello"
27-
127.0.0.1:6379>
29+
```
30+
31+
Set a value and an expiry time.
32+
```
2833
127.0.0.1:6379> SET anotherkey "will expire in a minute" EX 60
2934
OK
3035
```
3136

37+
Conditionally set a value.
38+
```
39+
127.0.0.1:6379> SET foo "Initial Value"
40+
OK
41+
127.0.0.1:6379> GET foo
42+
"Initial Value"
43+
127.0.0.1:6379> SET foo "New Value" IFEQ "Initial Value"
44+
OK
45+
127.0.0.1:6379> GET foo
46+
"New Value"
47+
```
48+
3249
## Patterns
3350

3451
**Note:** The following pattern is discouraged in favor of [the Redlock algorithm](../topics/distlock.md) which is only a bit more complex to implement, but offers better guarantees and is fault tolerant.

0 commit comments

Comments
 (0)