Modular system
4.0 The maximum change of Redis is the addition of the module system that allows users to extend and implement Redis itself does not have the function through code I have written, specific methods can refer antirez Bowen "Redis Loadable Module System": HTTP : //antirez.com/news/106
Because the module system is achieved by a high-level API, it is completely separated from the Redis kernel itself, without disturbing each other, the user can only enable this feature in need thereof, the following is redis.conf
the module loading methods described in:
################################## MODULES #####################################
# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
Currently it has been developed using this feature a variety of modules, such as Redis Labs developed a number of modules can be in http://redismodules.com see, in addition antirez themselves also use this feature to develop a neural network module: HTTPS : //github.com/antirez/neural-redis
Module feature allows users to Redis can be used as infrastructure and build more features on it, which gives Redis brought numerous new possibilities.
PSYNC 2.0
The new version of the PSYNC
command to solve some of the less than optimal places an older version of Redis when copying:
- In the old version of Redis, if one after FAILOVER become the new master node from the server, then the other from the node must copy the full amount at the time of this copy of the new primary. In Redis 4.0, from the new master server, and in dealing with such cases, the use of part of replication under conditions permitting.
- In the old version of Redis, one from the server if the restart, then it must be re-copied the whole amount of the primary server, in Redis 4.0, as long as conditions permit, will use part of the master-slave replication in dealing with this situation.
Cache eviction policy optimization
Last Frequently Used newly added cache eviction policy, detailed information, see antirez Bowen "Random Notes ON Improving the LRU algorithm at The Redis": http://antirez.com/news/109
In addition eviction policy Redis 4.0 is also optimized the existing cache, so that they can be more robust, efficient, fast and accurate.
Non-blocking DEL, FLUSHDB and FLUSHALL
Before Redis 4.0, users use the DEL
command to delete a large volume of bonds, or the use FLUSHDB
and FLUSHALL
delete keys contain a large number of databases , the servers are likely to cause obstruction.
To solve this problem, Redis 4.0 added new UNLINK
command, which is the DEL
asynchronous version of the command, which you can delete the specified key on a background thread to perform inside to avoid the server to block as much as possible:
redis> UNLINK fruits
(integer) 1
Because of some historical reasons, synchronize deletions of DEL
command will remain.
In addition, Redis 4.0 FLUSHDB
and FLUSHALL
two new commands added ASYNC
option to delete the database with this option will be in the background thread:
redis> FLUSHDB ASYNC
OK
redis> FLUSHALL ASYNC
OK
Exchange database
Redis 4.0 database command Another modification is the addition of SWAPDB
command, which can be interchanged on the specified two databases: for example, by executing the command SWAPDB 0 1
, we can become the original database 0 1 database, and the original database a database becomes 0.
The following is a use SWAPDB
example:
redis> SET your_name "huangz" -- 在数据库 0 中设置一个键
OK
redis> GET your_name
"huangz"
redis> SWAPDB 0 1 -- 互换数据库 0 和数据库 1
OK
redis> GET your_name -- 现在的数据库 0 已经没有之前设置的键了
(nil)
redis> SELECT 1 -- 切换到数据库 1
OK
redis[1]> GET your_name -- 之前在数据库 0 设置的键现在可以在数据库 1 找到
"huangz" -- 证明两个数据库已经互换
Mixed format persistence RDB-AOF
Redis 4.0 Added RDB-AOF mixing persistence format, which is an optional feature, after turning on this function, a file rewriting AOF produced will contain AOF format and contents format RDB, RDB format wherein content for existing data records, and the memory AOF format for recording data change has occurred recently, so that the advantages of both can RDB Redis persistence and persistence while AOF - both to rapidly generate a weight write files in case of problems can quickly load data.
This feature can aof-use-rdb-preamble
be turned on options, redis.conf
file records the use of this option:
# When rewriting the AOF file, Redis is able to use an RDB preamble in the
# AOF file for faster rewrites and recoveries. When this option is turned
# on the rewritten AOF file is composed of two different stanzas:
#
# [RDB file][AOF tail]
#
# When loading Redis recognizes that the AOF file starts with the "REDIS"
# string and loads the prefixed RDB file, and continues loading the AOF
# tail.
#
# This is currently turned off by default in order to avoid the surprise
# of a format change, but will at some point be used as the default.
aof-use-rdb-preamble no
The inner presence instruction
It added a new MEMORY
command, which can be used to inspect memory usage, and corresponding memory management operations:
redis> MEMORY HELP
1) "MEMORY USAGE <key> [SAMPLES <count>] - Estimate memory usage of key"
2) "MEMORY STATS - Show memory usage details"
3) "MEMORY PURGE - Ask the allocator to release memory"
4) "MEMORY MALLOC-STATS - Show allocator internal stats"
Wherein, using the MEMORY USAGE
subcommand can be estimated given key memory required to store:
redis> SET msg "hello world"
OK
redis> SADD fruits apple banana cherry
(integer) 3
redis> MEMORY USAGE msg
(integer) 62
redis> MEMORY USAGE fruits
(integer) 375
Use MEMORY STATS
sub-command to view the current memory usage Redis:
redis> MEMORY STATS
1) "peak.allocated"
2) (integer) 1014480
3) "total.allocated"
4) (integer) 1014512
5) "startup.allocated"
6) (integer) 963040
7) "replication.backlog"
8) (integer) 0
9) "clients.slaves"
10) (integer) 0
11) "clients.normal"
12) (integer) 49614
13) "aof.buffer"
14) (integer) 0
15) "db.0"
16) 1) "overhead.hashtable.main"
2) (integer) 264
3) "overhead.hashtable.expires"
4) (integer) 32
17) "overhead.total"
18) (integer) 1012950
19) "keys.count"
20) (integer) 5
21) "keys.bytes-per-key"
22) (integer) 10294
23) "dataset.bytes"
24) (integer) 1562
25) "dataset.percentage"
26) "3.0346596240997314"
27) "peak.percentage"
28) "100.00315093994141"
29) "fragmentation"
30) "2.1193723678588867"
Use MEMORY PURGE
sub-command may require the distributor to release more memory:
redis> MEMORY PURGE
OK
Use MEMORY MALLOC-STATS
sub-command to display the internal state of the dispenser:
redis> MEMORY MALLOC-STATS
Stats not supported for the current allocator
Compatible with NAT and Docker
Redis 4.0 and the NAT compatible Docker , in particular the use redis.conf
documented in:
########################## CLUSTER DOCKER/NAT support ########################
# In certain deployments, Redis Cluster nodes address discovery fails, because
# addresses are NAT-ted or because ports are forwarded (the typical case is
# Docker and other containers).
#
# In order to make Redis Cluster working in such environments, a static
# configuration where each node known its public address is needed. The
# following two options are used for this scope, and are:
#
# * cluster-announce-ip
# * cluster-announce-port
# * cluster-announce-bus-port
#
# Each instruct the node about its address, client port, and cluster message
# bus port. The information is then published in the header of the bus packets
# so that other nodes will be able to correctly map the address of the node
# publishing the information.
#
# If the above options are not used, the normal Redis Cluster auto-detection
# will be used instead.
#
# Note that when remapped, the bus port may not be at the fixed offset of
# clients port + 10000, so you can specify any port and bus-port depending
# on how they get remapped. If the bus-port is not set, a fixed offset of
# 10000 will be used as usually.
#
# Example:
#
# cluster-announce-ip 10.1.1.5
# cluster-announce-port 6379
# cluster-announce-bus-port 6380