Basic Configuration
# Redis Profile Example # When you need to specify the memory size for a configuration item, you must bring the unit, # The usual format is 1k 5GB 4m, etc: # # 1k = + bytes# 1kb = bytes# 1m => ; 1000000 bytes# 1MB = 1024*1024 bytes# 1g = 1000000000 bytes# 1GB = 1024*1024*1024 bytes## units are case insensitive, you write 1K 5G B 4M Line # By default, Redis is not running as a daemon, and if you want it to run in the background, you can change it to Yes. # when Redis is running as a daemon, it writes a process ID that is PID to the/var/run/redis.pid file. Daemonize No # When Redis runs as a daemon, it writes the PID default to the/var/run/redis.pid file, # But you can customize the file location here. Pidfile/var/run/redis.pid # Listening port number, default is 6379, if you set to 0, Redis will not listen to any client connection on the socket. Port 6379 # Maximum number of TCP listeners # # # in a high-concurrency environment, you need to increase this value to avoid a slow client connection. # The Linux kernel will silent this value to/proc/sys/net/core/somaxconn corresponding value, # so you have to modify these two values to achieve your expectations. Tcp-backlog 511 # By default, Redis can connect to listening clients on all valid network interfaces on the server. # If you just want it to listen to one or more network interfaces, you're bound to one IP or multiple ips. </span>## example, multiple IPs are separated by spaces: # # Bind 192.168.1.100 10.0.0.1# bind 127.0.0.1 # Specifies the path of the UNIX socket. # # unixsocket/tmp/redis.sock# unixsocketperm 755 # Specifies how many seconds after a client is idle to close the connection (0 is unrestricted) Timeout 0 # TCP heartbeat packet. # # If set to nonzero, when communication with the client is lackingSend TCP ACKs to the client using So_keepalive. # This is all useful, mainly by two reasons: # 1) Detect Dead peers# 2) Take the connection alive from the point of view of network# equipment in the MI ddle.## on Linux, the specified value (in seconds) are the period used to send acks.# Note this to close the connection the Double of the time is needed.# on other kernels the period depends on the kernel configuration.## A reasonable value for This option is seconds.# recommended a reasonable value is 60 seconds tcp-keepalive 0 # Specify Logging level # Redis supports a total of four levels: Debug, verbose, notice, warning, The default is verbose# Debug records a lot of information for developing and testing # Varbose useful information, unlike debug will record so many # notice ordinary verbose, often used in production environment # warning Only very important or critical information is logged to the log loglevel notice # Specify the location of the log file logfile "" # to log to the system log, change it to yes,# and optionally update other syslog parameters to meet your requirements # Syslog-enabled No # Sets the identity of the syslog. # syslog-ident Redis # Sets the facility of the syslog, which must be a value between USER or LOCAL0-LOCAL7. # syslog-facility Local0 # Sets the number of databases. # The default database is DB 0, you can use Select <dbid> command on each connection to select a different database, # but dbid must be a value between 0 and databasees-1 databases 16 ######### ####################### snapshot ################################## to disk: # # Format: Save < interval (seconds) > < write times >## according to the given time Interval and number of writes save data to Disk # # # The following example means: # 900 seconds if at least 1 key values change, save # 300 seconds if at least 10 key values change, save # 60 seconds If there are at least 10,000 keys Value changes, save # # Note: You can disable the Save function by commenting out all the save lines. # can also be directly an empty string to achieve deactivation: # save "" Save 1save 10save 60 10000 # By default, Redis will stop accepting writes if the last background save for Redis fails, # This is a tough Way to let the user know that the data is not persisted to the disk correctly, # Otherwise no one will notice the disaster. # # If the background save process restarts work, Redis will also automatically allow write operations. # # However if you install a reliable monitor, you may not want Redis to do so, so you can change to No. Stop-writes-on-bgsave-error Yes # whether to use LZF compressed string when dump. RDB Database # Default is set to yes# if you want to save the child process save a bit of CPU, you set it to no, # but this data set may be Compare Big rdbcompression Yes # verify RDB file rdbchecksum Yes # Set dump file location Dbfilename Dump.rdb # working Directory # For example, the above dbfilename only specifies the file name, # but it will be written to this directory. This configuration item must be a directory, not a file name. Dir./################################# master-slave copy ################################# # master-slave copy. Use slaveof to make one Redis instance a copy of another Reids instance. # Note that this only needs to be configured on the slave. # # slaveof <masterip> <masterport> # If master requires password authentication, set it here # Masterauth <master-password> # When a slave loses contact with master, or the copy is in progress, the # Slave may behave in two ways: # 1) If yes, slave will still answer the client request, but the returned data may be stale, # or the data may be empty at the time of the first synchronization # # 2) If no, the # Slave will return when you execute a command other than info he salveof A "SYNC with Master in progress" error, #slave-serve-stale-data Yes # You can configure whether a slave entity accepts write operations. # storing some short-lived data through a write operation can be useful for a slave instance, because data writes to slave are more likely to be deleted because of the relative number of resynchronization from master. # However, if the client is writing to a misconfigured configuration, it can also cause some problems. # # from Redis version 2.6, the default slaves is read-only. # # Note:read Only slaves is not designed to being exposed to untrusted clients# on the Internet. It ' s just a protection layer against misuse of the instance.# still a read only slave exports by default all the Administr Ative commands# such as CONFIG, DEBUG, and so forth. To a limited extent your can improve# security of read only slaves using ' Rename-command ' to shadow all the# administrative /Dangerous commands.# Note: read-only slaves is not designed to be exposed to untrusted clients on the Internet. # It's just a layer of protection against misuse instances. Slave-read-only Yes # slaves in aSend a ping command to the server within a predefined interval of time. # You can change this time interval. The default is 10 seconds. # # Repl-ping-slave-period # Following option sets the replication timeout for:# set master-slave replication Expiration # 1) Bulk transfer I/O D Uring SYNC, from the point of view of slave.# 2) Master Timeout from the point of view of slaves (data, pings). # 3) Slave Timeout from the point of view of Masters (replconf ACK pings). # # It's important to make sure that this value is greater than the value# specified for repl-ping-slave-period otherwise a timeout would be detected# every time there was low traffic Between the master and the slave.# this value must be greater than Repl-ping-slave-period # # repl-timeout # Disable tcp_nodelay on the slave Socket after sync?## If you select "Yes" Redis would use a smaller number of TCP packets and# less bandwidth to send data t o Slaves. But this can add a delay for# the data to appear on the slave side and up to milliseconds with# Linux kernels using a DEFA Ult configuration.## If you select ' No ' the delay for data to appear on the slave sIDE will# is reduced but more bandwidth'll be used for replication.## by default we optimize for low latency, but in ver Y high traffic conditions# or when the master and slaves is many hops away, turning this to ' yes ' may# be a good idea.rep L-disable-tcp-nodelay No # Sets the master-slave replication capacity size. This backlog is a buffer used to store slave data when a slaves is disconnected, so when a slave wants to reconnect and usually does not want to resynchronize all the time, # just partial synchronization is enough, just pass the part of the data that slave lost when disconnected. # # The biggest the replication backlog, the longer the time the slave can be# disconnected and later be able to perform a Partial resynchronization.# The larger the value, the longer the salve can disconnect. # # The backlog is only allocated once there are at least a slave connected.## repl-backlog-size 1MB # After a master have no Longer connected slaves for some time, the backlog# would be freed. The following option configures the amount of seconds that# need to elapse, starting from the time the last slave Disconne CTED, for# the backlog buffer to be freed.# at some point, master no longer connects Slaves,backlog will be released. # # A value of 0 means to NEVer release the backlog.# if set to 0, it means that the backlog is never released. # # Repl-backlog-ttl 3600 # When Master does not work properly, Redis Sentinel picks a new master,# from slaves, the smaller the value, the more it will be selected, but if it is 0, it means that s Lave cannot be selected. # # Default priority is 100. Slave-priority # It's possible for a master to stop accepting writes if there be less than# N slaves connected, Havi ng a lag less or equal than M seconds.## the N slaves need to is in ' online ' state.## the lag in seconds, which must be < = The specified value, is calculated from# The last ping received from the slave, which is usually sent every second.## Th Is option does not GUARANTEES that N replicas would accept the write, but# would limit the window of exposure for lost write s in case not enough slaves# is available, to the specified number of seconds.## for example-require at least 3 slaves With a lag <= ten seconds use:## min-slaves-to-write 3# min-slaves-max-lag 10## Setting One or the other to 0 disables The feature.## by default Min-slaves-to-write are set to 0 (feature Disabled) and# Min-slaves-max-lag is set to 10.
Security Options
################################## SECURITY ################################### # Sets the password to be used before any other specified client connection is made. # Warning: Because the Redis speed is quite fast, an external user can make a 150K password attempt in a second on a better server, which means you need to specify very very strong passwords to prevent brute force cracking # # Requirepass foobared # command renaming. # # 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. # # # Rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52## If you want to delete a command, simply rename it to a null character "", as follows: # # Rename-command CONFIG ""
Redis Constraints
################################### LIMITS #################################### # Set the maximum number of client connections at the same time, default Unlimited, The number of client connections that Redis can open at the same time is the maximum number of file descriptors that the Redis process can open, # if you set maxclients 0, it means no restrictions. # when the number of client connections reaches the limit, Redis closes the new connection and returns the max number of clients reached error message to the client # # maxclients 128 # Specify the Redis max memory limit, Redis will load data into memory at boot time, and Redis will attempt to purge expired or expiring key# Redis and also remove the empty list object when this method is processed, the maximum memory setting is still reached, and the write operation is no longer possible. But still can read operation # # Note: Redis new VM mechanism, will put key memory, value will be stored in the Swap area # # MaxMemory's settings are more suitable for using Redis as a memcached-like cache to use, Instead of being a true db. # when using Redis as a real database, memory usage will be a big expense # MaxMemory <bytes> # What data does Redis choose to delete when the memory reaches its maximum value? There are five ways to choose # # VOLATILE-LRU using the LRU algorithm to remove key (LRU: Most recently used Least recently used) # ALLKEYS-LRU using the LRU algorithm to remove any key# vo Latile-random-----Remove a random key, which sets the expiration time, key# allkeys->random, remove a random keys, any key# Volatile-ttl, removes the expiring key ( Minor TTL) # noeviction-not remove any can, just return a write error # # Note: For the above policy, if there is no appropriate key can be removed, when writing Redis will return an error # # Write commands include: Set SETNX set Ex append# incr decr rpush lpush rpushx LpushX Linsert lset rpoplpush sadd# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby# zunionstor E zinterstore hset hsetnx hmset hincrby incrby decrby# getset mset msetnx exec sort## default is: # # Maxmemory-policy Volati LE-LRU # LRU and minimal TTL algorithms are not accurate algorithms, but relatively accurate algorithms (in order to save memory), optionally you can choose sample size for detection. # redis Default Gray Select 3 samples for detection, you can set by Maxmemory-samples # # Maxmemory-samples 3
aof Configuration
############################## APPEND only mode ############################### # By default, Redis backs up database mirroring to disk asynchronously in the background, However, this backup is very time-consuming, and the backup can not be very frequent, if the occurrence of such as power cuts, unplug and other conditions, it will result in a relatively large range of data loss. # so Redis offers another more efficient way to database backup and disaster recovery. # when append only mode is turned on, Redis appends every write request received to the Appendonly.aof file, and when Redis restarts, the previous state is recovered from the file. # But this will cause the appendonly.aof file to be too large, so Redis also supports the BGREWRITEAOF instructions and re-organizes the appendonly.aof. # You can turn on asynchronous dumps and AOF appendonly No # AOF file name (default: "Appendonly.aof") # appendfilename Appendonly.aof # Redis Support Three kinds of synchronization aof file policy: # # No: Do not synchronize, the system to operate. faster.# Always:always indicates 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 set it to "no", let the OS decide when to execute # or instead want to make the data more secure you can also set it to "always" # # If you are unsure, use "everysec". # Appendfsync Alwaysappendfsync everysec# appendfsync No # AOF policy is set to always or EVERYSEC, the background processing process (background save or AOF log rewrite) performs a large number of I/O operations # in some Linux configurations, too long Fsync () requests are blocked. Note Now that there is no fix, even if Fsync is working on another thread # # in order to mitigate this problem, you can set this parameter no-appendfsync-on-rewrite## this means the while anotherChild was saving the durability of Redis is# the same as "Appendfsync none", that's pratical terms means that it is# Possi Ble to lost up to $ seconds of log in the worst scenario (with the# default Linux settings). # If You have latency probl EMS turn this to "yes". Otherwise Leave it as# "No" that's the safest pick from the point of view of Durability.no-appendfsync-on-rewrite No # Au Tomatic rewrite of the append only file.# AOF auto Rewrite # When the AOF file grows to a certain size, Redis is able to invoke bgrewriteaof to rewrite the log file # # It works like this: Redis remembers The size of the file after some 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 rewrite feature will start # and need to specify a minimum size for aof overrides, which is used to block cases where the file is small but grows very large also to rewrite the aof file # settings percentage Turn off this feature for 0 auto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64MB
log File
################################## 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., only the command execution time # # can be set by two parameters slow log: One is to tell Redis how much time to execute the parameter Slowlog-log-slower-than (subtlety), # The other is the length of the slow log. When a new command is recorded, the oldest command is removed from the queue # The time below is in subtle micro-units, so 1000000 represents a minute. # Note Setting a negative number will turn off slow logging, while setting to 0 will force each command to be logged Slowlog-log-slower-than 10000 # No limit on log length, just be aware that it consumes memory # can be passed Slowlog RESET Reclaim memory consumed by slow logs Slowlog-max-len 1024
Advanced Configuration
############################### 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 you can set both of these thresholds # Redis hash corresponds to value inside is actually a hashmap, there will actually 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, without the use of real hashmap structure, the corresponding value Redisobject encoding 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 512hash-max-zipmap-value # 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 compact storage format. List-max-ziplist-entries 512list-max-ziplist-value # 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 # 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 128zset-max-ziplist-value # Redis will use 1 milliseconds of CPU time every 100 milliseconds to re-hash the Redis hash table, # # 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
specify include additional configurations
################################## includes ################################### # Specifies that other configuration files are included, You can use the same configuration file between multiple Redis instances on the same host, while each instance has its own specific profile # include/path/to/local.conf# include/path/to/other.conf
Redis configuration file in a detailed