-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
nav: | ||
title: Elasticsearch | ||
position: 10 | ||
position: 5 | ||
|
||
--- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
--- | ||
nav: | ||
title: Redis | ||
position: 7 | ||
|
||
--- | ||
|
||
# Redis | ||
|
||
[Redis](https://redis.io/docs/latest/get-started/) is an in-memory data storage, that offers high performance and can be used as a cache, message broker, and database. It is a key-value store that supports various data structures like strings, hashes, lists, sets, and sorted sets. | ||
Especially in high-performance and high-throughput scenarios it can give better results, than relying on a traditional relational database. | ||
Therefore, multiple adapter exist in shopware, to offload some tasks from the DB to Redis. | ||
|
||
However, as the data that is stored in Redis differs and also the access patterns to this data differ, it makes sense to use different Redis instances with different configurations for different tasks. | ||
|
||
The data stored in Redis can be roughly classified into those three categories: | ||
1. Ephemeral data: This data is not critical and can be easily recreated when lost, e.g. caches. | ||
2. Durable, but "aging" data: This data is important and can not easily be recreated, but the relevance of the data decreases over time, e.g. sessions. | ||
3. Durable and critical data: This data is important and can not easily be recreated, e.g. carts, number ranges. | ||
|
||
## Ephemeral data | ||
|
||
As ephemeral data can easily be restored and is most often used in cases where high performance matters, this data can be stored with no durable persistence. | ||
This means the data is only stored in memory and is lost when the Redis instance is restarted. | ||
|
||
For key eviction policy you should use `volatile-lru`, which only automatically deletes data that is expired, as the application explicitly manages the TTL for each cache item. | ||
|
||
The caching data (HTTP-Cache & Object cache) is what should be stored in this instance. | ||
|
||
<PageRef page="../performance/caches" /> | ||
Check warning on line 30 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L30
Raw output
Check warning on line 30 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L30
Raw output
|
||
|
||
## Durable, but "aging" data | ||
|
||
As the data stored here is durable and should be persistent, even in the case of a Redis restart, it is recommended to configure the used Redis instance that it will not just keep the data in memory, but also store it on the disk. This can be done by using snapshots (RDB) and Append Only Files (AOF), refer to the [Redis docs](https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/) for details. | ||
|
||
`allkeys-lru` should be used as key eviction policy here, as by default more recent data is more important than older data, therefore the oldest values should be discarded, when Redis reach the max memory. | ||
|
||
The session data is what should be stored in this instance. | ||
|
||
<PageRef page="../performance/session" /> | ||
Check warning on line 40 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L40
Raw output
Check warning on line 40 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L40
Raw output
|
||
|
||
## Durable and critical data | ||
|
||
Again this is durable data, that can not easily be recreated, therefore it should be persisted as well. | ||
|
||
As the data is critical it is important to use a key eviction policy that will not delete data that is not expired, therefore `volatile-lru` should be used. | ||
|
||
The cart, number range, lock store and increment data is what should be stored in this instance. | ||
|
||
<PageRef page="../performance/cart-storage" /> | ||
Check warning on line 50 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L50
Raw output
Check warning on line 50 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L50
Raw output
|
||
|
||
<PageRef page="../performance/number-ranges" /> | ||
Check warning on line 52 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L52
Raw output
Check warning on line 52 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L52
Raw output
|
||
|
||
<PageRef page="../performance/lock-store" /> | ||
Check warning on line 54 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L54
Raw output
Check warning on line 54 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L54
Raw output
|
||
|
||
<PageRef page="../performance/increment" /> | ||
Check warning on line 56 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L56
Raw output
Check warning on line 56 in guides/hosting/infrastructure/redis.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/infrastructure/redis.md#L56
Raw output
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
nav: | ||
title: Cart Storage | ||
position: 65 | ||
|
||
--- | ||
|
||
# Cart Storage | ||
|
||
By default, shopware stores the cart in the database. This can be a performance bottleneck in scenarios where high throughput is required (e.g., thousands of orders per minute), especially if a DB cluster with a read/write-split is used. | ||
Additionally, as the content in that table can change quite quickly, it can lead to an explosion of the databases binlog file. | ||
|
||
Redis is better suited in high-throughput scenarios, therefore you should use Redis as storage for the cart in such scenarios. | ||
|
||
## Using Redis as storage | ||
|
||
To use Redis, create a `config/packages/shopware.yml` file with the following content: | ||
|
||
```yaml | ||
shopware: | ||
cart: | ||
redis_url: 'redis://host:port/dbindex?persistent=1' | ||
Check warning on line 22 in guides/hosting/performance/cart-storage.md GitHub Actions / LanguageTool[LanguageTool] guides/hosting/performance/cart-storage.md#L22
Raw output
|
||
``` | ||
It is recommended to use a persistent Redis connection to avoid connection issues in high-load scenarios. | ||
## Migrating between storages | ||
You can migrate the current carts from the DB to Redis by running the following CLI command: | ||
```shell | ||
bin/console cart:migrate {fromStorage} {redisUrl?} | ||
``` | ||
|
||
::: info | ||
Providing the redis URL is optional. If not provided, the value from the configuration will be used. If it is not configured in the yaml file, you need to provide the URL. | ||
::: | ||
|
||
For example, if you want to migrate from the default `SQL` storage to the high-performing `Redis` storage, the command is: | ||
|
||
```shell | ||
bin/console cart:migrate sql | ||
``` | ||
|
||
## Redis configuration | ||
|
||
As the information stored here is durable and should be persistent, even in the case of a Redis restart, it is recommended to configure the used Redis instance that it will not just keep the data in memory, but also store it on the disk. This can be done by using snapshots (RDB) and Append Only Files (AOF), refer to the [Redis docs](https://redis.io/docs/latest/operate/oss_and_stack/management/persistence/) for details. | ||
|
||
As key eviction policy you should use `volatile-lru`, which only automatically deletes carts that are expired, as otherwise you might risk of losing data. For a detailed overview of Redis key eviction policies see the [Redis docs](https://redis.io/docs/latest/develop/reference/eviction/). |