# Configuration

### Redis Configuration&#x20;

可於[**Redis網站**](https://redis.io/topics/config)下載各版本的**redis.conf**檔案，在檔案中以記載了每個參數的基本解釋。有關

### Maxmemory policies

有關記憶體配置政策，可以參考[**GCP網站**](https://cloud.google.com/memorystore/docs/redis/redis-configs)，包含如何分配Redis存取記憶記憶體的比例，以及超出記憶體上限限制後的刪除規則，亦整理於下方表格。

| Parameter                  | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Acceptable values                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **activedefrag**           | **Redis version 4.0, or later.** Works to free up instance memory tied up by [standard OSS Redis memory fragmentation behavior](https://redis.io/topics/memory-optimization).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | <p><code>no</code> (default)<br><code>yes</code><br></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| **lfu-decay-time**         | **Redis version 4.0, or later.** The time, in minutes, before the LFU frequency counter for a given key will be divided by two (or, if the counter is < 10, decremented by 1). See the [REDIS.CONF](https://raw.githubusercontent.com/antirez/redis/4.0/redis.conf) file for additional information.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | <p>Positive integers of the 'long' data type<br>(default=1)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| **lfu-log-factor**         | **Redis version 4.0, or later.** Determines how the frequency counter represents key hits. Before you modify the default configuration, read about how the `lfu-log-factor` configuration works in the [REDIS.CONF](https://raw.githubusercontent.com/antirez/redis/4.0/redis.conf) file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | <p>Positive integers of the 'long' data type<br>(default=10)</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| **maxmemory-gb**           | Designates an adjustable limit at which your eviction policy takes effect. For example, if you have a 10 GB instance and you set `maxmemory-gb` to `8`, your eviction policy takes effect when your data occupies 8 GB of your instance memory. This leaves you 2 GB of memory as overhead. By default `maxmemory-gb` is set to your instance capacity. For details on how to best use the `maxmemory-gb` configuration, see the Memorystore [memory management best practices](https://cloud.google.com/memorystore/docs/redis/memory-management-best-practices).You can only [modify](https://cloud.google.com/memorystore/docs/redis/configuring-redis#setting_and_updating_configuration_parameters_with_the) the `maxmemory-gb` configuration using the `gcloud` command-line tool. The configuration is not available in the Google Cloud Console | <p>Number of GB expressed as a whole number or decimal.<br>Examples:<br><code>10</code> designates a <code>maxmemory-gb</code> of 10 GB.<br><code>1.5</code> designates a <code>maxmemory-gb</code> of 1.5 GB.<br><code>maxmemory-gb</code> can be reduced to a minimum of 20% of your instance capacity.</p>                                                                                                                                                                                                                                                                                                                                                                                                                             |
| **maxmemory-policy**       | <p>Specifies the behavior Redis follows when the instance data reaches the <code>maxmemory-gb</code> limit. Refer to <a href="https://cloud.google.com/memorystore/docs/redis/redis-configs#maxmemory_policies">Maxmemory policies</a> for a description of the behavior of each policy.<br><br>For additional information about the open source Redis maxmemory policies, see the open source Redis <a href="http://redis.io/topics/lru-cache">LRU cache page</a></p>                                                                                                                                                                                                                                                                                                                                                                                  | <p><code>noeviction</code><br><code>allkeys-lru</code><br><code>volatile-lru</code> (default)<br><code>allkeys-random</code><br><code>volatile-random</code><br><code>volatile-ttl</code><br><code>volatile-lfu</code> (Redis version 4.0 and higher)<br><code>allkeys-lfu</code> (Redis version 4.0 and higher)<br></p>                                                                                                                                                                                                                                                                                                                                                                                                                  |
| **notify-keyspace-events** | Allows clients to subscribe to notifications on certain keyspace events. See the [Redis Keyspace Notifications](http://redis.io/topics/notifications) page on the Redis site for more information.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | <p><code>""</code> (default)<br><code>K</code><br>Keyspace events, published with **keyspace@** prefix.<br><code>E</code><br>Keyevent events, published with **keyevent@** prefix.<br><code>g</code><br>Generic commands (non-type specific) like DEL, EXPIRE, or RENAME<br><code>$</code><br>String commands<br><code>l</code><br>List commands<br><code>s</code><br>Set commands<br><code>h</code><br>Hash commands<br><code>z</code><br>Sorted set commands<br><code>x</code><br>Expired events (events generated every time a key expires)<br><code>e</code><br>Evicted events (events generated when a key is evicted for maxmemory)<br><code>A</code><br>Alias for g$lshzxe, so that the "AKE" string means all the events.<br></p> |
| `stream-node-max-bytes`    | **Redis version 5.0, or later.** The Redis stream data structure uses a radix tree to store items. The `stream-node-max-bytes` parameter designates the maximum number of bytes available to store items in a single tree node. Once this limit is reached new items are stored in a new tree node.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | <p>Integers 0 and higher.<br>(default=4096)<br>0 designates a tree node of unlimited size.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `stream-node-max-entries`  | **Redis version 5.0, or later.** The Redis stream data structure uses a radix tree to store items. The `stream-node-max-entries` parameter designates the number of items that can be stored in a single node. When this limit is reached, new items are stored in a new tree node.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | <p>Integers 0 and higher.<br>(default=100)<br>0 designates a tree node with an unlimited number of items.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `timeout`                  | The number of seconds before idle client connections are terminated. However, if `timeout` is set to `0` idle clients do not timeout and remain connected until the client issues the termination.You can only [modify](https://cloud.google.com/memorystore/docs/redis/configuring-redis#setting_and_updating_configuration_parameters_with_the) the `timeout` configuration using the `gcloud` command-line tool. The configuration is not available in the Google Cloud Console                                                                                                                                                                                                                                                                                                                                                                      | <p>0 (default)<br>Integers >= 120<br>Unit = <strong>seconds</strong></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |

### 補充：GCP Redis不可修改的參數

| Parameter                  | Default |
| -------------------------- | ------- |
| `lua-time-limit`           | 5000    |
| `hash-max-ziplist-entries` | 2048    |
| `hash-max-ziplist-value`   | 1024    |
| `list-max-ziplist-size`    | -2      |
| `list-compress-depth .`    | 0       |
| `set-max-intset-entries`   | 512     |
| `zset-max-ziplist-entries` | 1024    |
| `zset-max-ziplist-value`   | 1024    |
| `hll-sparse-max-byte`      | 3000    |
| `activerehashing`          | 是       |
| `hz`                       | 10      |
| `databases`                | 16      |
| `maxclients`               | 65000   |
| `slowlog-log-slower-than`  | 10000   |
| `slowlog-max-len`          | 128     |
