From aa2aeb3a8b719652fc533bc12f3c5aee4c5f278f Mon Sep 17 00:00:00 2001 From: Sarthak Aggarwal Date: Tue, 10 Dec 2024 13:47:35 -0800 Subject: [PATCH 1/5] Documentation for SET IFEQ (#189) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR adds the documentation to support https://github.com/valkey-io/valkey/pull/1324 --------- Signed-off-by: Sarthak Aggarwal Signed-off-by: Viktor Söderqvist Co-authored-by: Viktor Söderqvist --- commands/set.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/commands/set.md b/commands/set.md index 08969f76..d3467cbe 100644 --- a/commands/set.md +++ b/commands/set.md @@ -12,23 +12,40 @@ The `SET` command supports a set of options that modify its behavior: * `PXAT` *timestamp-milliseconds* -- Set the specified Unix time at which the key will expire, in milliseconds (a positive integer). * `NX` -- Only set the key if it does not already exist. * `XX` -- Only set the key if it already exists. +* `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. * `KEEPTTL` -- Retain the time to live associated with the key. -* `!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. +* `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. 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. ## Examples +Basic usage ``` 127.0.0.1:6379> SET mykey "Hello" OK 127.0.0.1:6379> GET mykey "Hello" -127.0.0.1:6379> +``` + +Set a value and an expiry time. +``` 127.0.0.1:6379> SET anotherkey "will expire in a minute" EX 60 OK ``` +Conditionally set a value. +``` +127.0.0.1:6379> SET foo "Initial Value" +OK +127.0.0.1:6379> GET foo +"Initial Value" +127.0.0.1:6379> SET foo "New Value" IFEQ "Initial Value" +OK +127.0.0.1:6379> GET foo +"New Value" +``` + ## Patterns **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. From c367da60e9dbc3900a8cc6d3f6674839fdd598be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 10 Dec 2024 22:52:26 +0100 Subject: [PATCH 2/5] Update PHP Redlock impl. doc (#195) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the PHP Redlock impl. link and move it as the 1st mentioned PHP impl. as it is the most popular and the only library which supports both https://github.com/phpredis/phpredis and https://github.com/predis/predis clients. Signed-off-by: Michael Voříšek --- topics/distlock.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topics/distlock.md b/topics/distlock.md index a464ec75..a9b7b355 100644 --- a/topics/distlock.md +++ b/topics/distlock.md @@ -28,8 +28,8 @@ already available that can be used for reference. * [Redlock-py](https://github.com/SPSCommerce/redlock-py) (Python implementation). * [Pottery](https://github.com/brainix/pottery#redlock) (Python implementation). * [Aioredlock](https://github.com/joanvila/aioredlock) (Asyncio Python implementation). +* [RedisMutex](https://github.com/malkusch/lock#redismutex) (PHP implementation with both [Redis extension](https://github.com/phpredis/phpredis) and [Predis library](https://github.com/predis/predis) clients support). * [Redlock-php](https://github.com/ronnylt/redlock-php) (PHP implementation). -* [PHPRedisMutex](https://github.com/malkusch/lock#phpredismutex) (further PHP implementation). * [cheprasov/php-redis-lock](https://github.com/cheprasov/php-redis-lock) (PHP library for locks). * [rtckit/react-redlock](https://github.com/rtckit/reactphp-redlock) (Async PHP implementation). * [Redsync](https://github.com/go-redsync/redsync) (Go implementation). From 397bc469de8d8c5134bcb03dc4a9edf38ae87c44 Mon Sep 17 00:00:00 2001 From: "zhaozhao.zz" Date: Wed, 11 Dec 2024 20:03:06 +0800 Subject: [PATCH 3/5] Detail the issue of redirection occurring within a transaction. (#168) doc for https://github.com/valkey-io/valkey/pull/895 --------- Signed-off-by: zhaozhao.zz Co-authored-by: Madelyn Olson --- topics/transactions.md | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/topics/transactions.md b/topics/transactions.md index a8ee2614..5f23f48a 100644 --- a/topics/transactions.md +++ b/topics/transactions.md @@ -119,10 +119,52 @@ MULTI +OK INCR a b c -ERR wrong number of arguments for 'incr' command +EXEC +-EXECABORT Transaction discarded because of previous errors. ``` This time due to the syntax error the bad `INCR` command is not queued -at all. +at all. And the `EXEC` command will receive an `EXECABORT` error. + +When the `EXEC` command is processed, the server will check if a failover or slot migration has occurred since queuing the commands. +If either event has occurred, a `-MOVED` or `-REDIRECT` error will be returned if needed without processing the transaction. + +For cluster mode: + +``` +MULTI ==> +OK +SET x y ==> +QUEUED +slot {x} is migrated to other node +EXEC ==> -MOVED +``` + +For standalone mode: + +``` +MULTI ==> +OK +SET x y ==> +QUEUED +failover +EXEC ==> -REDIRECT +``` + +Before the `EXEC` command is processed, if a command accesses data that does not belong to the current node, +a `-MOVED` or `-REDIRECT` error will be returned immediately, and the `EXEC` command will receive an `EXECABORT` error. + +For cluster mode: + +``` +MULTI ==> +OK +SET x y ==> -MOVED +EXEC ==> -EXECABORT +``` + +For standalone mode: + +``` +MULTI ==> +OK +SET x y ==> -REDIRECT +EXEC ==> -EXECABORT +``` ## What about rollbacks? From 387bc9ae734de7634aac8dde4c023ff813bea7f6 Mon Sep 17 00:00:00 2001 From: "zhaozhao.zz" Date: Mon, 16 Dec 2024 20:24:05 +0800 Subject: [PATCH 4/5] Explanation of issues when using GET and NX/XX/IFEQ together in SET command (#199) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhaozhao.zz Co-authored-by: Viktor Söderqvist --- commands/set.md | 1 + 1 file changed, 1 insertion(+) diff --git a/commands/set.md b/commands/set.md index d3467cbe..4ce213fa 100644 --- a/commands/set.md +++ b/commands/set.md @@ -15,6 +15,7 @@ The `SET` command supports a set of options that modify its behavior: * `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. * `KEEPTTL` -- Retain the time to live associated with the key. * `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. + * Note: When `GET` is used together with `NX`/`XX`/`IFEQ`, it is impossible to determine whether the `SET` command executed successfully based on the reply alone. 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. From 373cc273349295903d6faee67a817729fe514bf1 Mon Sep 17 00:00:00 2001 From: "Kyle J. Davis" Date: Tue, 17 Dec 2024 13:43:26 -0700 Subject: [PATCH 5/5] Moves links to wayback machine, fixes one bad `s/redis/valkey/` (#201) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR moves links to antriez.com to the most recent wayback machine links. This ensures that the content that the docs point to is the intended content, it has proper https, and doesn't unexpectedly forward. Additionally, there was one improper search/replace that was reworded when the link was changed. Fixes #188 --------- Signed-off-by: Kyle J. Davis Co-authored-by: Viktor Söderqvist --- commands/pfcount.md | 2 +- topics/admin.md | 2 +- topics/distlock.md | 2 +- topics/history.md | 8 ++++---- topics/hyperloglogs.md | 2 +- topics/installation.md | 2 +- topics/lru-cache.md | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/commands/pfcount.md b/commands/pfcount.md index b8dbecc6..5d3609e5 100644 --- a/commands/pfcount.md +++ b/commands/pfcount.md @@ -58,4 +58,4 @@ The HyperLogLog, being a String, can be retrieved with `GET` and restored with ` The representation is neutral from the point of view of the processor word size and endianness, so the same representation is used by 32 bit and 64 bit processor, big endian or little endian. -More details about the HyperLogLog implementation can be found in [this blog post](http://antirez.com/news/75). The source code of the implementation in the `hyperloglog.c` file is also easy to read and understand, and includes a full specification for the exact encoding used for the sparse and dense representations. +More details about the HyperLogLog implementation can be found in [this blog post](https://web.archive.org/web/20241019222035/http://antirez.com/news/75). The source code of the implementation in the `hyperloglog.c` file is also easy to read and understand, and includes a full specification for the exact encoding used for the sparse and dense representations. diff --git a/topics/admin.md b/topics/admin.md index aa4ac2a9..f9a2661d 100644 --- a/topics/admin.md +++ b/topics/admin.md @@ -37,7 +37,7 @@ description: Advice for configuring and managing Valkey in production ### Security -* By default, Valkey does not require any authentication and listens to all the network interfaces. This is a big security issue if you leave Valkey exposed on the internet or other places where attackers can reach it. See for example [this attack](http://antirez.com/news/96) to see how dangerous it can be. Please check our [security page](security.md) and the [quick start](quickstart.md) for information about how to secure Valkey. +* By default, Valkey does not require any authentication and listens to all the network interfaces. This is a big security issue if you leave Valkey exposed on the internet or other places where attackers can reach it. See for example [this attack](https://web.archive.org/web/20241019230117/http://antirez.com/news/96) to see how dangerous it can be. Please check our [security page](security.md) and the [quick start](quickstart.md) for information about how to secure Valkey. ## Running Valkey on EC2 diff --git a/topics/distlock.md b/topics/distlock.md index a9b7b355..425ce7ae 100644 --- a/topics/distlock.md +++ b/topics/distlock.md @@ -227,4 +227,4 @@ Thanks in advance! ## Analysis of Redlock --- -1. Martin Kleppmann [analyzed Redlock here](https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html). A counterpoint to this analysis can be [found here](http://antirez.com/news/101). +1. Martin Kleppmann [analyzed Redlock here](https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html). A counterpoint to this analysis can be [found here](https://web.archive.org/web/20241209045142/http://antirez.com/news/101). diff --git a/topics/history.md b/topics/history.md index 316c5c48..66ba9117 100644 --- a/topics/history.md +++ b/topics/history.md @@ -52,7 +52,7 @@ In March, 2010, Sanfilippo was hired by [VMware](https://vmware.com) to work on Redis and Redis Tools. In his blog post [VMware: the new Redis home][antirez-vmware], he writes: -[antirez-vmware]: http://oldblog.antirez.com/post/vmware-the-new-redis-home.html +[antirez-vmware]: https://web.archive.org/web/20241017012850/http://oldblog.antirez.com/post/vmware-the-new-redis-home.html > Not only Redis will remain a totally open source project, but Redis Tools will > be open sourced also (and this was an idea I got from VMware itself!). @@ -92,7 +92,7 @@ The following year, 2014, Garantia Data [changed its name to Redis Labs][redisla [redislabs]: https://techcrunch.com/2014/01/29/database-provider-garantia-data-makes-another-name-change-this-time-to-redis-labs/ In 2015, Salvatore left Pivotal for Redis Labs. He writes in his blog post -[Thanks Pivotal, Hello Redis Labs](http://antirez.com/news/91): +[Thanks Pivotal, Hello Redis Labs](https://web.archive.org/web/20241123010805/http://antirez.com/news/91): > Redis Labs was willing to continue what VMware and Pivotal started. I'll be > able to work as I do currently, spending all my time in the open source side @@ -113,12 +113,12 @@ BSD][will-remain-bsd]. He repeated this promise in [a comment on Hacker News][hn-always-bsd], writing “let me assure you that Redis remains and always will remain, open source, BSD license”. -[antirez-remain-bsd]: http://antirez.com/news/120 +[antirez-remain-bsd]: https://web.archive.org/web/20241111062719/http://antirez.com/news/120 [will-remain-bsd]: https://redis.io/blog/redis-license-bsd-will-remain-bsd/ [hn-always-bsd]: https://news.ycombinator.com/item?id=17819392 In 2020, Salvatore Sanfilippo announced in his blog post [The end of the Redis -adventure](http://antirez.com/news/133) that he was stepping back as the Redis +adventure](https://web.archive.org/web/20241123005834/http://antirez.com/news/133) that he was stepping back as the Redis maintainer, handing over the maintenance to Yossi Gottlieb and Oran Agra at Redis Labs. The two created a “core team” to maintain the project and invited Itamar Haber from Redis Labs, Zhao Zhao from Alibaba and Madelyn Olson from diff --git a/topics/hyperloglogs.md b/topics/hyperloglogs.md index ec940ec6..8a719262 100644 --- a/topics/hyperloglogs.md +++ b/topics/hyperloglogs.md @@ -88,4 +88,4 @@ The HyperLogLog can estimate the cardinality of sets with up to 18,446,744,073,7 ## Learn more -* [Valkey new data structure: the HyperLogLog](http://antirez.com/news/75) has a lot of details about the data structure and its implementation in Valkey. +* This blog post on [the HyperLogLog data structure](https://web.archive.org/web/20241019222035/http://antirez.com/news/75) has a lot of details about the data structure and its implementation in Valkey. diff --git a/topics/installation.md b/topics/installation.md index 5abc8f9a..444c3922 100644 --- a/topics/installation.md +++ b/topics/installation.md @@ -75,7 +75,7 @@ By default Valkey binds to **all the interfaces** and has no authentication at a 3. Use the `requirepass` option to add an additional layer of security so that clients will be required to authenticate using the `AUTH` command. 4. Use [spiped](https://www.tarsnap.com/spiped.html) or another SSL tunneling software to encrypt traffic between Valkey servers and Valkey clients if your environment requires encryption. -Note that a Valkey instance exposed to the internet without any security [is very simple to exploit](http://antirez.com/news/96), so make sure you understand the above and apply **at least** a firewall layer. After the firewall is in place, try to connect with `valkey-cli` from an external host to confirm that the instance is not reachable. +Note that a Valkey instance exposed to the internet without any security [is very simple to exploit](https://web.archive.org/web/20241119215618/http://antirez.com/news/96), so make sure you understand the above and apply **at least** a firewall layer. After the firewall is in place, try to connect with `valkey-cli` from an external host to confirm that the instance is not reachable. ## Use Valkey from your application diff --git a/topics/lru-cache.md b/topics/lru-cache.md index 6d1b549e..21c7b532 100644 --- a/topics/lru-cache.md +++ b/topics/lru-cache.md @@ -132,7 +132,7 @@ the `CONFIG SET maxmemory-samples ` command, is very simple. ## The LFU mode -The [Least Frequently Used eviction mode](http://antirez.com/news/109) is available as an alternative to LRU. +The [Least Frequently Used eviction mode](https://web.archive.org/web/20241019222228/http://antirez.com/news/109) is available as an alternative to LRU. This mode may work better (provide a better hits/misses ratio) in certain cases. In LFU mode, Valkey will try to track the frequency of access of items, so the ones used rarely are evicted. This means