Skip to content

Commit

Permalink
Merge remote-tracking branch 'valkey/main' into doc-fixes-part-3
Browse files Browse the repository at this point in the history
  • Loading branch information
zuiderkwast committed Dec 18, 2024
2 parents f0b009c + 373cc27 commit 6749afb
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 12 deletions.
2 changes: 1 addition & 1 deletion commands/pfcount.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
22 changes: 20 additions & 2 deletions commands/set.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,41 @@ 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: 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.

## 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.
Expand Down
4 changes: 2 additions & 2 deletions topics/distlock.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
8 changes: 4 additions & 4 deletions topics/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!).
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion topics/hyperloglogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion topics/lru-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ the `CONFIG SET maxmemory-samples <count>` 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
Expand Down
44 changes: 43 additions & 1 deletion topics/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit 6749afb

Please sign in to comment.