Configure redis
You can run the redis-server command to directly start the service without any configuration information. All configurations use the default settings. To enable the configuration file, you can append the absolute path of the configuration file to the redis-server command. By default, a redis. conf file is generated in the redis directory after redis is compiled. This file is the default template of the redis configuration file.
Src/redis-server redis. conf
Redis supports many parameters, but all have default values.
● Daemonize:
By default, redis is not running in the background. If you need to run in the background, change the value of this item to yes.
● Pidfile
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.
● Bind
Specify that redis only receives requests from this IP address. If this parameter is not set, all requests are processed. It is best to set this parameter in the production environment.
● Port
Listening port. The default value is 6379.
● Timeout
Set the timeout time for client connection, in seconds. When the client does not send any commands during this period, the connection is closed.
● Loglevel
Log levels are classified into four levels: Debug, verbose, notice, and warning. Notice is generally enabled in the production environment.
● Logfile
Configure the log file address. By default, standard output is used, which is printed in the window of the command line terminal.
● Databases
Set the number of databases. You can use the SELECT command to switch between databases. The default database is 0.
● Save
Set the frequency of redis database images.
If (when 10000 keys change within 60 seconds ){
Back up images
} Else if (10 keys changed in 300 seconds ){
Back up images
} Else if (one keys changed in 900 seconds ){
Back up images
}
● Rdbcompression
Whether to perform compression during image backup.
● Dbfilename
The name of the backup file.
● Dir
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.
● Slaveof
Set the database as the slave database of another database.
● Masterauth
This parameter is specified here when the primary database connection requires password verification.
● Requirepass
Set the password to be used before other settings are made after the client connects. 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.
● Maxclients
Limit the number of customers connected at the same time. When the number of connections exceeds this value, redis will no longer receive other connection requests, and the client will receive an error message when trying to connect.
● Maxmemory
Set the maximum memory available for redis. When the memory is full, if you still receive the SET command, redis will first try to remove the key with expire information, regardless of whether the key expires. During deletion, the key will be deleted according to the expiration time, and the key to be expired will be deleted first. If all keys with expire information are deleted, an error is returned. In this way, redis will not receive write requests, but only get requests. Maxmemory settings are suitable for using redis as a cache similar to memcached.
● Appendonly
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. 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, so redis also supports the bgrewriteaof command to reorganize appendonly. Aof. Therefore, we recommend that you disable the image and enable appendonly. aof in the production environment. You can also rewrite appendonly. aof every day when there is less access.
● Appendfsync
Set the synchronization frequency of the appendonly. aof file. Always indicates that the write operation is synchronized every time, while everysec indicates that the write operation is accumulated and synchronized every second. This configuration is required based on actual business scenarios.
● VM-Enabled
Whether to enable virtual memory support. Because redis is a memory database and cannot receive new write requests when the memory is full, redis 2.0 provides virtual memory support. However, in redis, all keys are stored in the memory. When the memory is insufficient, only the value is placed in the SWAp zone. This ensures that although the virtual memory is used, the performance is basically not affected. At the same time, you must note that you should set VM-max-memory to enough to put down all your keys.
● VM-Swap-File
Set the swap file path for the virtual memory.
● VM-max-memory
Set the maximum physical memory size that redis will use after enabling virtual memory. The default value is 0. redis will put all of its swap files into swap files to use as little physical memory as possible. In the production environment, you need to set this value according to the actual situation. It is best not to use the default 0.
● VM-page-size
Set the page size of the virtual memory. If your value is large, for example, you need to place allArticleIf you want to store small content, set it to a smaller value.
● VM-pages
Set the total number of pages for the swap file. Note that the page table information is stored in the physical memory, and each 8 pages occupies one byte in Ram. Total virtual memory size = VM-page-size * VM-pages.
● VM-max-threads
Sets the number of threads simultaneously used by VM Io. Because the data is encoded and decoded during memory exchange, I/O devices cannot support many concurrent reads and writes on the hardware, however, if the value of the vlaue you saved is relatively large, you can set this value to a greater value to improve the performance.
● Glueoutputbuf
Put the small output cache together so that multiple responses can be sent to the client in a TCP packet. I am not very clear about the specific principle and actual effect. Therefore, you can set the value to yes if you are not sure.
● Hash-max-zipmap-entries
Hash data structure is introduced in redis 2.0. 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, the two thresholds can be set here.
● Activerehashing
After it is enabled, redis uses a CPU time of 1 ms every 100 milliseconds to re-hash the hash table of redis, which can reduce the 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 yes to release the memory as quickly as possible.
The official redis documentation provides some suggestions for the use of VMS:When your key is small and the value is large, it will be better to use VM. this saves a lot of memory. when your key is not hour, you can consider using some very method to convert a large key into a large value. For example, you can consider combining the key and value into a new value. it is best to use Linux ext3 and other file systems that support sparse files to save your swap files. the VM-max-threads parameter can be used to set the number of threads accessing the swap file. It is recommended that the number of threads not exceed the number of machine cores. If it is set to 0, all operations on swap files are serial. it may cause a long delay, but it guarantees data integrity.