# Redis configuration file
# When you need to configure memory size in the configuration, you can use 1k, 5GB, 4M and other similar formats, which are converted in the following ways (case insensitive)
#
# 1k =
bytes
# 1kb = 1024x768 bytes
# 1m = 1000000 bytes
# 1MB =
1024*1024 bytes
# 1g = 1000000000 bytes
# 1GB = 1024*1024*1024
bytes
#
# memory configuration case is the same. For example, 1GB 1Gb 1GB 1gB
# Daemonize No by default, Redis is not running in the background, and if it needs to run in the background, change the value of the item to Yes
Daemonize
Yes
# when Redis runs in the background, Redis defaults to placing the PID file in/var/run/redis.pid, which you can configure to a different address.
#
When running multiple Redis services, you need to specify a different PID file and port
Pidfile/var/run/redis.pid
# Specify the port on which Redis runs, default is 6379
Port 6379
# Specifies that Redis receives only requests from that IP address, and if not set, all requests are processed,
# It is best to set this item in a production environment
# bind
127.0.0.1
# Specify the path for the UNIX sockets that would be used to listen for
#
Incoming connections. There is no default, so Redis would not listen
# on a
UNIX socket when not specified.
#
# Unixsocket/tmp/redis.sock
#
Unixsocketperm 755
# Sets the time-out period in seconds for client connections. When the client has not issued any instructions during this time, the connection is closed
# 0 is to turn off this setting
Timeout
0
# Specify logging Levels
# Redis supports a total of four levels: Debug, verbose, notice, warning, default = verbose
#
Debug logs a lot of information for development and testing
# Varbose useful information, not as much as debug will record
#
Notice common verbose, often used in production environments
# warning only very important or serious information will be recorded in the log
LogLevel
Debug
# Configure log file address
# default value is stdout, standard output, if background mode is output to/dev/null
#logfile
StdOut
Logfile/var/log/redis/redis.log
# To enable logging to the system logger, just set ' syslog-enabled ' to
Yes
# and optionally update the other syslog parameters to suit your
Needs.
# syslog-enabled No
# Specify the syslog identity.
# syslog-ident Redis
# Specify the syslog facility. Must be USER or between local0-local7.
#
Syslog-facility local0
# Number of available databases
# The default value is 16, the default database is 0, and the database range is between 0-(database-1)
Databases 16
################################ Snapshot
#################################
#
# Save data to disk in the following format:
#
# Save
<seconds> <changes>
#
#
Indicates how many times the update operation will synchronize data to the RDB of the data file.
# equivalent to conditional trigger fetch snapshot, this can be combined with multiple conditions
#
#
For example, the settings in the default configuration file set three conditions
#
# Save 900 1 900 seconds at least 1 keys have been changed
# Save 300
At least 300 keys are changed in 10 300 seconds
# Save 60 10000 60 seconds at least 10,000 keys have been changed
Save 900 1
Save 300 10
Save 60 10000
# Whether to compress data when storing to a local database (persisted to an RDB file), by default Yes
Rdbcompression Yes
# Local Persistent database file name, default value is Dump.rdb
Dbfilename Dump.rdb
# working Directory
#
# The path to the file placement of the database mirroring backup.
#
The path here is configured separately from the file name because Redis writes the state of the current database to a temporary file when it is being backed up, and when the backup is complete,
#
The temporary file is replaced with the file specified above, and the temporary file and the backup file configured above will be placed in the specified path.
#
#
The AoF file will also be stored under this directory
#
# Note that a directory, not a file, must be developed here
Dir./
################################# replication
#################################
# Master-slave replication. Set the database from the database for the other database.
#
Set the IP address and port of the master service when this machine is a Slav service, and it will automatically synchronize data from master when Redis boots
#
# slaveof
<masterip> <masterport>
# When the master service is password protected (password set with Requirepass)
# Slav The password of the service connection master
#
#
Masterauth <master-password>
# When a connection is lost from the library to the host or the replication is in progress, there are two modes of operation from the hangar:
#
# 1)
If Slave-serve-stale-data is set to Yes (the default setting), the request from the corresponding client will continue from the library
#
# 2)
If slave-serve-stale-data refers to no, any request outside the info and SLAVOF commands will return a
# error "SYNC with
Master in Progress "
#
Slave-serve-stale-data Yes
# from the library, the pings is sent to the main library at a time interval. This interval can be set by Repl-ping-slave-period, which is 10 seconds by default
#
#
Repl-ping-slave-period 10
# Repl-timeout Set the main library bulk data transfer time or ping reply interval, the default value is 60 seconds
#
Make sure that repl-timeout is greater than repl-ping-slave-period
# Repl-timeout 60
################################## Safety
###################################
# Set the password to be used before any other specified client connection is made.
#
Warning: Because the Redis speed is quite fast, under a better server, an external user can make a 150K password attempt in a second, which means you need to specify a very strong password to prevent brute force.
#
#
Requirepass foobared
# command renamed.
#
# in a shared environment, you can rename a relatively dangerous command. For example, the name of Config is a character that is not easy to guess.
#
#
Example:
#
# Rename-command CONFIG
B840fc02d524045429941cc15f59e41cb7be6c52
#
#
If you want to delete a command, simply rename it to a null character "", as follows:
#
# Rename-command CONFIG ""
################################### constraints
####################################
# Set the maximum number of client connections at the same time, the default is no limit, Redis can open the number of client connections for the Redis process can open the maximum number of file descriptors,
# If you set
MaxClients 0, indicating no restrictions.
# when client connections reach the limit, Redis closes the new connection and returns max number of clients to the client
Reached error message
#
# maxclients 128
# Specifies the Redis maximum memory limit, which will be loaded into memory by Redis at boot time, and Redis will attempt to clear the expired or expiring key first when it reaches the maximum memory.
#
Redis also removes empty list objects
#
#
When this method is processed, the maximum memory setting is still reached and the write operation is no longer available, but the read operation is still possible
#
#
Note: Redis's new VM mechanism will store the key in memory, and value will be stored in the swap area.
#
#
The MaxMemory setting is more appropriate for using Redis as a memcached-like cache than for a real db.
#
When using Redis as a real database, memory usage would be a big expense.
# maxmemory <bytes>
# What data does Redis choose to delete when the memory reaches its maximum value? There are five different ways to choose
#
# VOLATILE-LRU
Use the LRU algorithm to remove key (LRU: Recently used Least recently used) that set an expiration time
# ALLKEYS-LRU
Removing any key using the LRU algorithm
# volatile-random, removing the random key set over expiration time
#
Allkeys->random, remove a random key, any key
# Volatile-ttl
Remove the expiring key (minor TTL)
# noeviction not remove any can, just return a write error
#
#
Note: For the above policy, if no appropriate key can be removed, Redis will return an error when writing
#
# Write commands include: Set SETNX
Setex Append
# incr DECR rpush lpush rpushx lpushx linsert LSet
Rpoplpush Sadd
# sinter Sinterstore sunion sunionstore sdiff sdiffstore
Zadd Zincrby
# zunionstore Zinterstore hset hsetnx hmset Hincrby Incrby
Decrby
# getset Mset msetnx exec sort
#
# default is:
#
#
Maxmemory-policy VOLATILE-LRU
# LRU and minimal TTL algorithms are not accurate algorithms, but relatively accurate algorithms (in order to save memory), optionally you can choose the sample size to detect.
#
Redis default Gray Select 3 samples for detection, you can set through Maxmemory-samples
#
# Maxmemory-samples
3
############################## AOF ###############################
#
By default, Redis backs up database mirroring to disk asynchronously in the background, but the backup is time-consuming and cannot be backed up very often, resulting in a wide range of data loss if conditions such as power cuts, unplug, etc., occur.
#
So Redis offers another more efficient way to database backup and disaster recovery.
# Open Append
After only mode, Redis appends every write request received to the Appendonly.aof file, and when Redis restarts, the previous state is recovered from the file.
#
However, this will cause the appendonly.aof file to be too large, so Redis also supports the BGREWRITEAOF directive, and re-organizes the appendonly.aof.
#
You can open asynchronous dumps and AOF at the same time.
AppendOnly No
# aof file name (default: "Appendonly.aof")
# Appendfilename Appendonly.aof
# Redis supports three different policies for synchronizing aof files:
#
# No: Do not synchronize, the system to operate. Faster.
# Always:
Always means that each write operation is synchronized. Slow, safest.
# Everysec: Indicates that the write operation is cumulative and synchronized once per second.
Compromise.
#
# default is "Everysec", according to speed and security compromise this is the best.
#
If you want Redis to run more efficiently, you can also set the "no" to let the operating system decide when to execute
#
Or instead, you can set the data to be more secure.
#
# use "Everysec" if you're not sure.
# Appendfsync Always
Appendfsync everysec
# Appendfsync No
# When the AOF policy is set to always or EVERYSEC, the background processing process (background save or AOF log rewrite) performs a number of I/O operations
#
In some Linux configurations, too long Fsync () requests are blocked. Note that there is now no fix, even if fsync is processing on another thread
#
#
To mitigate this problem, you can set the following parameter No-appendfsync-on-rewrite
#
# This means the while
Another child was saving the durability of Redis is
# the same as "Appendfsync
None ", that in pratical terms means.
# possible to lost up to 30
Seconds of Log in the worst scenario
# default Linux
Settings).
#
# If You have latency problems turn the "yes". Otherwise
Leave it as
# "No" that's the safest pick from the point of view of
Durability.
No-appendfsync-on-rewrite No
# Automatic Rewrite of the append only file.
# AOF Auto Rewrite
#
Redis can call bgrewriteaof to rewrite log files when the AoF file grows to a certain size
#
#
It works like this: Redis remembers the size of the file after the last log (if it has not been rewritten since the boot, the day size is determined at boot time)
#
#
The base size is compared with the current size. If the size is now larger than the base size, the override feature will start
#
At the same time, you need to specify a minimum size for the AOF rewrite, which prevents the file from being rewritten even though it is small but grows very large aof
# set Percentage
Turn this feature off for 0
Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64MB
################################## SLOW LOG
###################################
# Redis Slow log records commands that exceed a specific execution time. Execution time does not include I/O calculations such as connecting clients, returning results, etc., just the command execution time
#
#
You can set slow log with two parameters: one is to tell Redis how much time is logged for the parameters Slowlog-log-slower-than (subtle),
#
The other is the length of the slow log. The oldest command is removed from the queue when a new command is recorded
# The time below is in subtle micro-units, so 1000000 stands for one minute.
#
Note A negative number will turn off slow logging, and setting to 0 will force each command to be logged
Slowlog-log-slower-than 10000
# There is no limit to the log length, just be aware that it consumes memory
# can be passed Slowlog RESET
Reclaim memory consumed by slow logs
Slowlog-max-len 1024
################################ VM ###############################
# # warning! Virtual Memory is deprecated in Redis 2.4
# # # The use of
Virtual Memory is strongly discouraged.
# Virtual Memory allows Redis to work with datasets bigger than the
Actual
# Amount of RAM needed to hold the whole datasets in memory.
# in
order to doing so very used keys is taken in memory and the other keys
# is
Swapped into a swap file, similarly to what operating systems do
# with
Memory pages.
#
# To enable VM just set ' vm-enabled ' to Yes, and set the
Following three
# VM parameters accordingly to your needs.
Vm-enabled No
# vm-enabled Yes
# This is the path of the Redis swap file. As you can guess, swap
Files
# can ' t be shared by different Redis instances, so make sure to use a
Swap
# file for every Redis process is running. Redis would complain if
The
# swap file is already on use.
#
# The best kind of storage for the
Redis swap file (that's accessed at random)
# is a Solid state Disk
(SSD).
#
# * * * * * WARNING * * * If you are using a shared hosting the default
of putting
# The swap file under/tmp is not secure. Create a dir with access
Granted
#-Redis User and configure Redis to create the swap file
there.
Vm-swap-file/tmp/redis.swap
# Vm-max-memory configures the VM to use at max the specified amount
Of
# RAM. Everything that DEOs not fit would be swapped on disk *if* possible,
That
# is, if there are still enough contiguous space in the swap
File.
#
# with vm-max-memory 0 The system would swap everything it can. Not
A good
# default, just specify the max amount of RAM can in bytes, but
It ' s
# better to leave some margin. For instance specify an amount of
Ram
# That's more or less between and 80% of your free
Ram.
Vm-max-memory 0
# Redis swap files are split into pages. An object can be saved using
Multiple
# contiguous pages, but pages can ' t be shared between different
Objects.
# So if your page was too big, small objects swapped out on disk would
Waste
# A lot of space. If You page was too small, there is less space in the
Swap
# file (assuming configured the same number of total swap file
pages).
#
# If You use a lot of small objects, use a page size of 32 or
bytes.
# If You use a lot of the big objects, use a bigger page size.
# If
Unsure, use the default:)
Vm-page-size 32
# Number of total memory pages in the swap file.
# Given that page
Table (a bitmap of free/used pages) is taken in memory,
# every 8 pages on
Disk would consume 1 byte of RAM.
#
# The total swap size is vm-page-size *
Vm-pages
#
# with the default of 32-bytes memory pages and 134217728 pages
Redis would
# Use a 4 GB swap file, that would use the MB of RAM for the page
Table.
#
# It ' s better to use the smallest acceptable value for your
Application,
# But the default was large in order-to-work
Conditions.
Vm-pages 134217728
# Max Number of VM I/O threads running at the same time.
# This threads
is used to read/write data from/to swap file, since they
# also Encode and
Decode objects from disk to memory or the reverse, a bigger
# Number of
Threads can help with big objects even if they can ' t
# I/O itself
As the physical device may is able to couple with many
# reads/writes
Operations at the same time.
#
# The special value of 0 turn off threaded
I/O and enables the blocking
# Virtual Memory
implementation.
Vm-max-threads 4
############################### Advanced CONFIG
###############################
# When the hash contains more than the specified number of elements and the largest element does not exceed the critical,
#
The hash will be stored in a special encoding (greatly reduced memory usage), where these two thresholds can be set
# Redis
Hash corresponds to value inside is actually a hashmap, actually there will be 2 different implementations,
#
This hash of the members is relatively young redis in order to save memory will be similar to a one-dimensional array of compact storage, rather than the real hashmap structure, the corresponding value
The encoding of Redisobject is Zipmap,
#
When the number of members increases, it automatically turns into a true hashmap, at which point encoding is HT.
Hash-max-zipmap-entries
512
Hash-max-zipmap-value 64
# The list data type how many nodes below will use a compact storage format for pointers.
#
The list data type node value size is less than how many bytes are in a compact storage format.
List-max-ziplist-entries
512
List-max-ziplist-value 64
# Set data type internal data if all are numeric, and how many nodes are included the following are stored in a compact format.
Set-max-intset-entries
512
# Zsort data type How many nodes below will use a compact storage format for pointers.
#
Zsort data Type node value size is less than how many bytes are in a compact storage format.
Zset-max-ziplist-entries
128
Zset-max-ziplist-value 64
# Redis will use 1 milliseconds of CPU time every 100 milliseconds to re-hash the Redis hash table, which can reduce the use of memory
#
#
When you have a very strict real-time requirement in your usage scenario, you cannot accept Redis's occasional 2 millisecond delay on requests, and configure this as No.
#
#
If you don't have such strict real-time requirements, you can set it to Yes so that you can free up memory as quickly as possible
activerehashing Yes
################################## includes
###################################
# Specifies that other profiles can be used to use the same configuration file across multiple Redis instances on the same host, while each instance has its own specific configuration file
#
Include/path/to/local.conf
# include/path/to/other.conf
"Go" Redis configuration file