Detailed description of the redis configuration file

Source: Internet
Author: User
Tags allkeys password protection shared hosting

# Redis configuration file

# When the memory size needs to be configured in the configuration, you can use 1 k, 5 GB, 4 M and other similar formats, the conversion method is as follows (Case Insensitive)
#
#1 k = & gt; 1000 bytes
# 1kb => 1024 bytes
#1 m => 1000000 bytes
#1 mb => 1024*1024 bytes
#1g => 1000000000 bytes
#1 gb => 1024*1024*1024 bytes
#
# The memory configuration is the same in case. For example, 1 gb 1 Gb 1 GB 1 gB

# Daemonize no redis does not run in the background by default. If you need to run it in the background, change the value of this item to yes.
Daemonize yes

# When redis is running in the background, Redis puts the pid file in/var/run/redis. pid by default. You can configure it to another address.
# When running multiple redis services, you must specify different pid files and ports.
Pidfile/var/run/redis. pid

# Specify the port on which redis runs. The default value is 6379.
Port 6379

# Specify that redis only receives requests from this IP address. If this parameter is not set, all requests will be processed,
# It is best to set this item in the production environment
# Bind 127.0.0.1

# Specify the path for the unix socket that will be used to listen
# Incoming connections. There is no default, so Redis will not listen
# On a unix socket when not specified.
#
# Unixsocket/tmp/redis. sock
# Unixsocketperm 755

# Set the timeout time for client connection, in seconds. When the client does not send any commands during this period, close the connection.
#0: disable this setting.
Timeout 0

# Specify the log record level
# Redis supports four levels: debug, verbose, notice, and warning. The default value is verbose.
# Debug records a lot of information for development and testing
# Varbose useful information, not as many as debug records
# Notice common verbose, usually used in the production environment
# Warning only records very important or serious information.
Loglevel debug

# Configure the log file address
# The default value is stdout, which is standard output. If it is in the background mode, it is output to/dev/null.
# Logfile stdout
Logfile/var/log/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 and database-1.
Databases 16

################################ Snapshot ####### ##########################
#
# Save data to the disk in the following format:
#
# Save <seconds> <changes>
#
# Indicates how long and how many update operations are performed, and the data is synchronized to the data file rdb.
# It is equivalent to triggering snapshot capturing by conditions, which can be used with multiple conditions
#
# For example, three conditions are set in the default configuration file.
#
# Save 900 1 900 seconds at least one key is changed
# Save 300 10 300 seconds at least 300 keys are changed
# Save 60 10000 at least 10000 keys are changed within 60 seconds

Save 900 1
Save 300 10
Save 60 10000

# Whether to compress the data stored in the local database to the rdb file. The default value is yes.
Rdbcompression yes

# Name of the local persistent database file. The default value is dump. rdb.
Dbfilename dump. rdb

# Working directory
#
# Path of the database image backup file.
# The path and file name must be configured separately because redis first writes the status of the current database to a temporary file during Backup. When the backup is complete,
# Replace the temporary file with the file specified above, and the temporary file and the backup file configured above will be placed in the specified path.
#
# AOF files will also be stored in this directory
#
# Note that a directory instead of a file must be created.
Dir ./

################################## Copy ###### ###########################

# Master-slave replication. Set this database to a slave database of another database.
# Set the IP address and port of the master service when the local machine is slav service. When Redis is started, it will automatically synchronize data from the master.
#
# Slaveof <masterip> <masterport>

# When password protection is set for the master service (use the password set by requirepass)
# Password for the slav service to connect to the master
#
# Masterauth <master-password>


# When the slave database loses connection with the host or the replication is in progress, the slave database has two running modes:
#
#1) If slave-serve-stale-data is set to yes (default), the slave database will continue the request from the corresponding client.
#
#2) If slave-serve-stale-data is no, any request other than the INFO and SLAVOF commands will return
# Error "SYNC with master in progress"
#
Slave-serve-stale-data yes

# The slave database will send PINGs to the master database at a time interval. You can set this time interval through repl-ping-slave-period. The default value is 10 seconds.
#
# Repl-ping-slave-period 10

# Repl-timeout: Set the batch data transmission time or ping reply interval of the master database. The default value is 60 seconds.
# Make Sure That repl-timeout is greater than repl-ping-slave-period
# Repl-timeout 60

################################## Security ##### ##############################

# Set the password required to specify any other before connecting the client.
# Warning: Because redis is quite fast, an external user can try a K password in one second on a better server, this means you need to specify a very powerful password to prevent brute-force cracking.
#
# Requirepass foobared

# Command rename.
#
# You can rename Dangerous commands in a shared environment. For example, you can name a CONFIG multiple as a character that is not easy to guess.
#
# Example:
#
# Rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# To delete a command, rename it as an empty character ", as shown below:
#
# Rename-command CONFIG ""

################################### Constraints #### ################################

# Set the maximum number of client connections at the same time. The default value is unlimited. The number of client connections that can be opened at the same time by Redis is the maximum number of file descriptors that can be opened by the Redis process,
# If maxclients 0 is set, no restrictions are imposed.
# When the number of client connections reaches the limit, Redis will close the new connection and return the max number of clients reached error message to the client.
#
# Maxclients 128

# Specify the maximum memory limit of apsaradb for Redis. Redis loads data to the memory at startup. After the maximum memory is reached, Redis first tries to clear the expired or expiring Key.
# Redis also removes empty list objects
#
# When this method is processed, it still reaches the maximum memory setting, and no write operation can be performed, but the read operation can still be performed.
#
# Note: Redis's new vm mechanism stores keys in memory and values in the swap area.
#
# Maxmemory settings are suitable for using redis as a cache similar to memcached, rather than a real DB.
# When Using Redis as a real database, memory usage is a huge overhead
# Maxmemory <bytes>

# When the maximum memory size is reached, what data does Redis choose to delete? There are five ways to choose from
#
# Volatile-lru-> use the LRU algorithm to remove the key with an expiration time (LRU: Recently Used Least Recently Used)
# Allkeys-lru-> remove any key using the LRU Algorithm
# Volatile-random-> remove a random key with an expiration time set
# Allkeys-> random-> remove a random key, any key
# Volatile-ttl-> remove the expired key (minor TTL)
# Noeviction-> NO removal is allowed, but a write error is returned.
#
# Note: For the above policy, if there is no suitable key to remove it, Redis will return an error when writing it.
#
# 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
#
# The default value is:
#
# Maxmemory-policy volatile-lru

# LRU and minimal TTL algorithms are not precise algorithms, but relatively precise algorithms (to save memory), you can select the sample size for detection at will.
# By default, three samples are grayed out for Redis detection. You can set them through maxmemory-samples.
#
# Maxmemory-samples 3

############################# AOF ######### ######################


# By default, redis asynchronously backs up database images to disks in the background, but this backup is time-consuming and cannot be performed frequently, if a fault occurs, such as power limit or power limit, it may cause a wide range of data loss.
# Redis provides another more efficient database backup and disaster recovery method.
# After the append only mode is enabled, redis will append each write operation request received to appendonly. in the aof file, when redis is restarted, the previous state will be restored from the file.
# However, this will cause the appendonly. aof file to be too large. Therefore, redis also supports the BGREWRITEAOF command to reorganize appendonly. aof.
# You can enable asynchronous dumps and AOF at the same time

Appendonly no

# AOF file name (default: "appendonly. aof ")
# Appendfilename appendonly. aof

# Redis supports three AOF file synchronization policies:
#
# No: Do not synchronize, the system will operate. Faster.
# Always: always indicates that all write operations are synchronized. Slow and Safest.
# Everysec: indicates that write operations are accumulated and synchronized once per second. Compromise.
#
# The default value is "everysec", which is the best compromise between speed and security.
# If you want to make Redis run more efficiently, you can also set it to "no" so that the operating system can decide when to execute
# Alternatively, you can set it to "always" to make data safer"
#
# If you are not sure, use "everysec ".

# Appendfsync always
Appendfsync everysec
# Appendfsync no

# When the AOF policy is set to always or everysec, a large number of I/O operations will be performed by background processing processes (stored in the background or overwritten AOF logs ).
# In some Linux configurations, too long fsync () requests are blocked. Note that there is no repair, even if fsync is processed in another thread
#
# To alleviate this problem, you can set the following parameter no-appendfsync-on-rewrite.
#
# This means that while another child is saving the durability of Redis is
# The same as "appendfsync none", that in pratical terms means that it is
# Possible to lost up to 30 seconds of log in the worst scenario (with
# Default Linux settings ).
#
# If you have latency problems turn this to "yes". Otherwise leave it
# "No" that is the safest pick from the point of view of durability.
No-appendfsync-on-rewrite no

# Automatic rewrite of the append only file.
# AOF automatic Rewriting
# When the AOF file grows to a certain size, Redis can call BGREWRITEAOF to rewrite the log file
#
# It works like this: Redis will remember the size of the file after the last log (if it has not been rewritten since it was started, the size of the day will be determined when it is started)
#
# Compare the basic size with the current size. If the current size is greater than the base size, the rewrite function will start
# At the same time, you need to specify a minimum size for AOF rewriting. This is used to prevent the AOF file from being overwritten even if the file is small but growing significantly.
# Disable this feature when percentage is set to 0

Auto-aof-rewrite-percentage 100
Auto-aof-rewrite-min-size 64 mb

################################## Slow log #### ###############################

# Redis Slow Log records commands that exceed the specified execution time. The execution time does not include I/O computing, such as connecting to the client and returning results. It is only the command execution time.
#
# You can set slow log using two parameters: one is to tell Redis how long it has been recorded to execute the slowlog-log-slower-than (subtle) parameter ),
# The other is the length of the slow log. When a new command is recorded, the earliest command will be removed from the queue.

# The following time is in a subtle microunit, so 1000000 represents one minute.
# Note that setting a negative number will disable slow logs, and setting it to 0 will force every command to record
Slowlog-log-slower-than 10000

# There is no limit on the log length, but note that it will consume memory
# You can use slowlog reset to 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 stronugly discouraged.

# Virtual Memory allows Redis to work with datasets bigger than the actual
# Amount of RAM needed to hold the whole dataset in memory.
# In order to do so very used keys are taken in memory while the other keys
# Are 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 you are running. Redis will complain if
# Swap file is already in 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
# Only to 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
# RAM. Everything that deos not fit will be swapped on disk * if * possible, that
# Is, if there is still enough contiguous space in the swap file.
#
# With vm-max-memory 0 the system will swap everything it can. Not a good
# Default, just specify the max amount of RAM you can in bytes, but it's
# Better to leave some margin. For instance specify an amount of RAM
# That's more or less between 60 and 80% of your free RAM.
Vm-max-memory 0

# Redis swap files is 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 is too big, small objects swapped out on disk will waste
# A lot of space. If you page is too small, there is less space in the swap
# File (assuming you configured the same number of total swap file pages ).
#
# If you use a lot of small objects, use a page size of 64 or 32 bytes.
# If you use a lot of 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 the page table (a bitmap of free/used pages) is taken in memory,
# Every 8 pages on disk will 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 will
# Use a 4 GB swap file, that will use 16 MB of RAM for the page table.
#
# It's better to use the smallest acceptable value for your application,
# But the default is large in order to work in most conditions.
Vm-pages 134217728

# Max number of vm I/O threads running at the same time.
# This threads are 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 help
# I/O itself as the physical device may not be able to couple with role
# 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 maximum number of elements does not exceed the critical value,
# Hash will be stored in a special encoding method that greatly reduces memory usage. Here we can set these two thresholds.
# The Value corresponding to Redis Hash is actually a HashMap, which has two different implementations,
# When there are few Members of this Hash, Redis will adopt a compact storage like a one-dimensional array to save memory, instead of a real HashMap structure. The corresponding value redisObject's encoding is zipmap,
# When the number of members increases, it is automatically converted into a real HashMap. In this case, encoding is ht.
Hhash-max-zipmap-entries 512
Hash-max-zipmap-value 64

# The number of nodes in the list data type follows the compact storage format of de-pointer.
# The number of bytes smaller than the node value of the list data type adopts the compact storage format.
List-max-ziplist-entries 512
List-max-ziplist-value 64

# If all the internal data of the set data type is of the numeric type and the number of nodes or less is stored in a compact format.
Set-max-intset-entries 512

# The following zsort data nodes use a compact storage format that removes pointers.
# Zsort uses a compact storage format when the node value is smaller than the number of bytes.
Zset-max-ziplist-entries 128
Zset-max-ziplist-value 64

# Redis uses a 1 ms CPU time every 100 milliseconds to re-hash the redis hash table, which can reduce memory usage
#
# When your application scenario requires strict real-time performance and Redis cannot accept a latency of 2 milliseconds from time to time for requests, set this parameter to no.
#
# If you do not have such strict real-time requirements, you can set it to yes to release the memory as quickly as possible.
Activerehashing yes

################################## Des ##### ##############################

# Specify other configuration files. You can use the same configuration file between multiple Redis instances on the same host, and each instance has its own specific configuration file.

# Include/path/to/local. conf
# Include/path/to/other. conf


This article is from the "ant nest" blog, please be sure to keep this source http://feihan21.blog.51cto.com/1364153/1299958

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.