Ability to set maxmemory settings
PROD-28654
Change-Id: I07ab91303516067d89493e94727f0e2cc68cf3c3
diff --git a/redis/files/2.2/redis.conf b/redis/files/2.2/redis.conf
index 4ae4b06..ea2271b 100644
--- a/redis/files/2.2/redis.conf
+++ b/redis/files/2.2/redis.conf
@@ -194,7 +194,11 @@
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
+{%- if pillar.redis.server.get('maxmemory', False) %}
+maxmemory {{ pillar.redis.server.maxmemory }}
+{%- else %}
# maxmemory <bytes>
+{%- endif %}
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached? You can select among five behavior:
@@ -218,6 +222,9 @@
# The default is:
#
# maxmemory-policy volatile-lru
+{%- if pillar.redis.server.get('maxmemory_policy', False) %}
+maxmemory-policy {{ pillar.redis.server.maxmemory_policy }}
+{%- endif %}
# LRU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can select as well the sample
@@ -225,7 +232,11 @@
# pick the one that was used less recently, you can change the sample size
# using the following configuration directive.
#
+{%- if pillar.redis.server.get('maxmemory_samples', False) %}
+maxmemory-samples {{ pillar.redis.server.maxmemory_samples }}
+{%- else %}
# maxmemory-samples 3
+{%- endif %}
############################## APPEND ONLY MODE ###############################
diff --git a/redis/files/2.8/redis.conf b/redis/files/2.8/redis.conf
index 55bcc44..68098fe 100644
--- a/redis/files/2.8/redis.conf
+++ b/redis/files/2.8/redis.conf
@@ -400,7 +400,11 @@
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
+{%- if server.get('maxmemory', False) %}
+maxmemory {{ server.maxmemory }}
+{%- else %}
# maxmemory <bytes>
+{%- endif %}
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
@@ -424,6 +428,9 @@
# The default is:
#
# maxmemory-policy volatile-lru
+{%- if server.get('maxmemory_policy', False) %}
+maxmemory-policy {{ server.maxmemory_policy }}
+{%- endif %}
# LRU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can select as well the sample
@@ -431,7 +438,11 @@
# pick the one that was used less recently, you can change the sample size
# using the following configuration directive.
#
+{%- if server.get('maxmemory_samples', False) %}
+maxmemory-samples {{ server.maxmemory_samples }}
+{%- else %}
# maxmemory-samples 3
+{%- endif %}
############################## APPEND ONLY MODE ###############################
diff --git a/redis/files/3.0/redis.conf b/redis/files/3.0/redis.conf
index fff790a..3558616 100644
--- a/redis/files/3.0/redis.conf
+++ b/redis/files/3.0/redis.conf
@@ -465,7 +465,11 @@
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
+{%- if server.get('maxmemory', False) %}
+maxmemory {{ server.maxmemory }}
+{%- else %}
# maxmemory <bytes>
+{%- endif %}
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
@@ -489,6 +493,9 @@
# The default is:
#
# maxmemory-policy noeviction
+{%- if server.get('maxmemory_policy', False) %}
+maxmemory-policy {{ server.maxmemory_policy }}
+{%- endif %}
# LRU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can tune it for speed or
@@ -499,7 +506,11 @@
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs a bit more CPU. 3 is very fast but not very accurate.
#
+{%- if server.get('maxmemory_samples', False) %}
+maxmemory-samples {{ server.maxmemory_samples }}
+{%- else %}
# maxmemory-samples 5
+{%- endif %}
############################## APPEND ONLY MODE ###############################
diff --git a/redis/files/5.0/redis.conf b/redis/files/5.0/redis.conf
index 22c2160..ada8626 100644
--- a/redis/files/5.0/redis.conf
+++ b/redis/files/5.0/redis.conf
@@ -577,7 +577,11 @@
# limit for maxmemory so that there is some free RAM on the system for replica
# output buffers (but this is not needed if the policy is 'noeviction').
#
+{%- if server.get('maxmemory', False) %}
+maxmemory {{ server.maxmemory }}
+{%- else %}
# maxmemory <bytes>
+{%- endif %}#
# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select among five behaviors:
@@ -609,6 +613,9 @@
# The default is:
#
# maxmemory-policy noeviction
+{%- if server.get('maxmemory_policy', False) %}
+maxmemory-policy {{ server.maxmemory_policy }}
+{%- endif %}
# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can tune it for speed or
@@ -619,7 +626,11 @@
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs more CPU. 3 is faster but not very accurate.
#
+{%- if server.get('maxmemory_samples', False) %}
+maxmemory-samples {{ server.maxmemory_samples }}
+{%- else %}
# maxmemory-samples 5
+{%- endif %}
# Starting from Redis 5, by default a replica will ignore its maxmemory setting
# (unless it is promoted to master after a failover or manually). It means
diff --git a/tests/pillar/server.sls b/tests/pillar/server.sls
index c1b18bb..94b5b71 100644
--- a/tests/pillar/server.sls
+++ b/tests/pillar/server.sls
@@ -4,4 +4,7 @@
bind:
address: 0.0.0.0
port: 6379
- protocol: tcp
\ No newline at end of file
+ protocol: tcp
+ maxmemory: 2gb
+ maxmemory_policy: noeviction
+ maxmemory_samples: 5
\ No newline at end of file