Redis can be customized by changing the values in redis.config file. In this blog, we will learn about redis config. We will understand how to change the various parameters in redis. So let’s get started.
Redis configuration file

The redis configuration is present inside redis.config file. The location of the configuration file in centos is /etc/redis.config.The location might vary based on the operating system on which the redis is installed.
Users also have the flexibility to define their own configuration file and use this file by starting the redis service.
Users can use the below command to start redis from the user-defined configuration file.
redis-server <path_to_conf_file>Redis Default configuration
When you install redis below is the default configuration setting that will be present in redis.
bind 127.0.0.1 -::1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
locale-collate ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-diskless-sync-max-replicas 0
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
aof-timestamp-enabled no
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-listpack-entries 512
hash-max-listpack-value 64
list-max-listpack-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-listpack-entries 128
zset-max-listpack-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yesUsers can also get configuration information from the command line by typing below command
127.0.0.1:6379> CONFIG GET *
1) "proc-title-template"
2) "{title} {listen-addr} {server-mode}"
3) "loglevel"
4) "notice"
5) "min-replicas-max-lag"
6) "10"
7) "repl-ping-replica-period"
8) "10"
9) "server_cpulist"
10) ""
11) "shutdown-on-sigterm"
12) "default"
13) "list-max-listpack-size"
14) "-2"
15) "cluster-allow-pubsubshard-when-down"
16) "yes"
17) "zset-max-ziplist-value"
18) "64"
19) "set-max-intset-entries"
20) "512"
21) "cluster-replica-no-failover"
22) "no"
.................................
.................................
.................................
.................................
367) "pidfile"
368) ""
369) "io-threads"
370) "1"
371) "cluster-migration-barrier"
372) "1"
373) "stream-node-max-bytes"
374) "4096"
375) "tls-ciphersuites"
376) ""
377) "slave-announce-ip"
378) ""
379) "appendfsync"
380) "everysec"
381) "dynamic-hz"
382) "yes"
383) "hash-max-ziplist-value"
384) "64"
127.0.0.1:6379>

Redis configuration command

Users can also use the redis cli to get the redis configuration details. Redis provides commands using which a user can get the redis configurations.
Type the below command to get all the configuration commands present in redis.
127.0.0.1:6379> help config CONFIG summary: A container for server configuration commands since: 2.0.0 group: server CONFIG GET parameter [parameter ...] summary: Get the values of configuration parameters since: 2.0.0 group: server CONFIG HELP summary: Show helpful text about the different subcommands since: 5.0.0 group: server CONFIG RESETSTAT summary: Reset the stats returned by INFO since: 2.0.0 group: server CONFIG REWRITE summary: Rewrite the configuration file with the in memory configuration since: 2.8.0 group: server CONFIG SET parameter value [parameter value ...] summary: Set configuration parameters to the given values since: 2.0.0 group: server
The important configuration commands are
- CONFIG
- CONFIG GET parameter [parameter …]
- CONFIG SET parameter [parameter …]
- CONFIG RESETSTAT
- CONFIG REWRITE
Redis config get
The Redis config get command is used to get the values of configuration parameters in the redis instance. The syntax for the redis GET command follows the below pattern
CONFIG GET <parameter>for example, type the below command to get the port of which the redis is running
127.0.0.1:6379> CONFIG GET port 1) "port" 2) "6379"

similarly, type the below command to get all the configurations present in redis.
CONFIG GET *
Redis config set
The Redis config set command is used to set the values of different variables in redis. The syntax for the redis set command follows the below pattern
CONFIG SET <parameter> <value>For example, type the CONFIG SET command to change the redis port to 6579
127.0.0.1:6379> CONFIG SET port 6579 OK
For example, type the CONFIG SET command to change the redis port to 6579
127.0.0.1:6379> CONFIG SET port 6579 OK
Redis configuration for production

Running a redis with default configuration in production is not recommended. Redis by default does not enable any security features. Below are a few configurations a user can change to run the redis into production.
Enable TLS/SSL in redis
One such setting is to enable SSL/TTLS in redis.To enable TLS user needs the below certificates
tls-cert-file
tls-key-file
tls-ca-cert-file Once you have these certificates, edit the /etc/redis.config file and add the certificates path
tls-cert-file /path/to/redis.crt
tls-key-file /path/to/redis.key
tls-ca-cert-file /path/to/ca.crtMore details can be found here
Enable Persistence in redis
The other important configuration which a user needs to change is the persistence label. There are many persistence options available in redis like:
- Redis persistence default(RDB)
- Append only file(AOF)
- No persistence
- RDB + AOF
RDB persistence is present by default. But RDB persistence is not enough to fully persist your redis data. Users need to enable AOF persistence as well. Follow my blog on Redis persistence to understand ways to enable persistence in redis.
Enable Replica in redis
The other important property which a user needs to be set up in redis is the replica properties. Users can modify the below replica properties as per their needs.
replica-serve-stale-data yes replica-read-only yes repl-diskless-sync yes repl-diskless-sync-delay 5 repl-diskless-sync-max-replicas 0 repl-diskless-load disabled repl-disable-tcp-nodelay no replica-priority 100 acllog-max-len 128 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no
Follow this blog to set up a replica in redis.
Conclusion
I hope you have liked this tutorial. Please do let me know if you are encountering any problems while following along.









