Redis full-Memory Operation
In some scenarios, we do not need to use Redis persistence. Instead, we need to use redis's memory database feature to achieve full memory operation and high performance.
Redis itself supports persistence. By synchronizing data in the memory to the disk at a certain interval or trigger operation, the persistence is ensured. Redis supports two persistence methods, one is Snapshotting and saved as dump. the rdb file is also the default method, and the Append-only file (aof) method is saved. aof file.
The Snapshot notifies redis of Snapshot persistence through the save or bgsave command. The save operation saves snapshots in the main thread. Because redis uses a main thread to process all client requests, this method will block all client requests. Therefore, it is not recommended. Note that each snapshot persistence completely writes the memory data to the disk, instead of synchronizing incremental data only. If the data volume is large, there will be more write operations, which will inevitably lead to a large number of disk IO operations, which may seriously affect the performance.
In the default snapshot rdb storage mode, the configuration in redis. conf is as follows:
Save 900 1 # if more than one key is modified within 900 seconds, the snapshot is saved.
Save 300 10 #300 seconds if more than 10 keys are modified, the snapshot is saved.
Save 60 10000
If we need to disable snapshots, just comment these lines and restart redis.
If the instance is running, you can use the redis-cli command.
# View the current configuration
Config get save
# Disable snapshots
Config set save ""
To update the configuration online. If the output is OK, the setting is successful.
AOF is more persistent than snapshot, because when aof persistence is used, redis writes
All commands are appended to the file through the write function (appendonly. aof by default ). When redis is restarted, it will re-execute the file
Save the write command to recreate the entire database content in the memory
The default configuration is as follows:
Appendonly yes // enable log append persistence
# Appendfsync always // immediately write data to the disk every time you receive the write command, which is the slowest, but ensures full persistence and is not recommended.
Appendfsync everysec // forcibly writes data to the disk once per second, which makes a good compromise between performance and persistence. We recommend that you
# Appendfsync no // It is fully dependent on the operating system and has the best performance. Persistence is not guaranteed.
We need to update the configuration file:
Appendfsync no
Online configuration update
# View the current configuration
Config get appendfsync
# Disable snapshots
Config set appendfsync no
With these two configurations, redis can run completely in the memory.
If you want to manually perform persistence, you can use bgsave and bgrewriteaof of Redis for manual persistence.
Install and test Redis in Ubuntu 14.04
Redis cluster details
Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis
Redis series-installation, deployment, and maintenance
Install Redis in CentOS 6.3
Learning notes on Redis installation and deployment
Redis. conf
Redis details: click here
Redis: click here
This article permanently updates the link address: