Redis configuration file details, redis configuration file

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

Redis configuration file details, redis configuration file
# 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 =>
1000 bytes
# 1kb => 1024 bytes
#1 m => 1000000 bytes
#1 mb =>
1024*1024 bytes
#1g => 1000000000 bytes
#1 gb => 1024x1024*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
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, often 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'
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
At least 300 keys are changed in 10 300 seconds.
# 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 (persistent 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
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 the repl-timeout value is greater than the repl-ping-slave-period value.
# 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 you set
Maxclients 0, indicating no restriction.
# When the number of client connections reaches the limit, Redis will close the new connection and return the max number of clients to the client.
Reached error message
#
# 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.
#
#
After 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 Redis is used 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 that has set the 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, you can remove it. When writing, Redis will return an error.
#
# 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. However, 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.
#
Therefore, redis provides another more efficient method for database backup and disaster recovery.
# Enable append
After the only mode, redis will append each write operation request received to the appendonly. aof file. When redis is restarted, it will restore the previous state from the file.
#
However, this will cause the appendonly. aof file to be too large, so 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 synchronization is performed for each write operation. 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
#
Or 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
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 some logs last time (if it has not been rewritten since it was started, the size of the day will be determined when it is started)
#
#
The base size is compared 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.
# Set percentage
If the value is 0, this feature is disabled.
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.
#
#
Two parameters can be used to set slow log: one is to tell Redis how much time has been recorded during execution of the parameter slowlog-log-slower-than (subtle ),
#
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
Reclaim memory consumed by slow logs
Slowlog-max-len 1024
################################ VM ####### ########################
### WARNING! Virtual Memory is deprecated in Redis 2.4
### The use
Virtual Memory is stronugly discouraged.
# Virtual Memory allows Redis to work with datasets bigger than
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
#
Memory pages.
#
# To enable VM just set 'vm-enabled' to yes, and set
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
Swap
# File for every redis process you are running. Redis will complain if
The
# Swap file is already in use.
#
# The best kind of storage for
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
Of
# 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,
It's
# Better to leave some margin. For instance specify an amount
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
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
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 (greatly reducing memory usage). Here we can set these two thresholds.
# Redis
The Value corresponding to the Hash is actually a HashMap, which has two different implementations,
#
When there are few Members of this Hash, Redis will adopt a compact storage method similar to one-dimensional array in order to save memory, instead of using the real HashMap structure, corresponding value
The encoding of redisObject is zipmap,
#
When the number of members increases, it is automatically converted to a real HashMap. In this case, encoding is ht.
Hash-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 is in 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
#
#
In your application scenario, if you have strict real-time requirements and cannot accept Redis's 2 ms latency for requests from time to time, 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

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.