Redis-AOF
AOF is log-based, similar to Oracle's redo,Mysql binlog log.
Configuration of Aof
Appendonly no # whether to turn on aof logging function
Appendfsync always # every command is immediately synchronized to aof. Safe, slow
Appendfsync everysec # compromise, write once per second
Appendfsync no # write work to the operating system, the operating system to determine the size of the buffer, unified write to aof. Low synchronization frequency and high speed
No-appendfsync-on-rewrite yes: # do you want to stop synchronizing aof while exporting rdb snapshots?
Auto-aof-rewrite-percentage 100 # aof file size compared to the size of the last rewrite, when the growth rate is 100%, rewrite
Auto-aof-rewrite-min-size 64mb # aof file, overridden when it exceeds at least 64m
Path to the appendfilename / var/dir/appendonly.aof # file
Do an experiment:
1, edit the redis.conf file
Enable the aof function and name aof filename
2 redis pkill-9
3, restart redis
[root@test-laoyangtest redis] # pkill-9 redis
[root@test-laoyangtest redis] #. / bin/redis-server. / redis.conf
4. View the aof file in the aof directory
[root@test-laoyangtest dir] # more laoyang-appendonly.aof-- empty
5, set a few keys, and then view the aof file
[root@test-laoyangtest redis] #. / bin/redis-cli
127.0.0.1 6379 > keys *
(empty list or set)
127.0.0.1 purl 6379 > set site www.woda.com
OK
127.0.0.1 purl 6379 > set www baidu.com
OK
The content of the aof file is generated.
[root@test-laoyangtest dir] # more laoyang-appendonly.aof
two
$6
SELECT
, 1
0
three
$3
Set
$4
Site
$12
Www.woda.com
* 3
$3
Set
$3
Www
9
Baidu.com
So there is a problem, if it is an automatically increasing value, the same key, 100 operations, aof back and forth to walk 100 records. How to solve?
All the key in memory has a specific state that inverts the value of key into a command.
For example, set age 1 and then incr age 100 times. So in the end, aof can directly set age 101 (this operation is called aof rewriting) to solve the growing problem of aof.
[these two parameters are controlled]
Auto-aof-rewrite-percentage 100 # aof file size compared to the size of the last rewrite, when the growth rate is 100%, rewrite
Auto-aof-rewrite-min-size 64mb # aof file, overridden when it exceeds at least 64m
Use the tool to write 2w commands
[root@test-laoyangtest redis] #. / bin/redis-benchmark-n 20000
= MSET (10 keys) =
20000 requests completed in 0.32 seconds
50 parallel clients
3 bytes payload
Keep alive: 1
95.03%