Introduction to New Features of Redis 4.0 Version
master-replica Redis 4.0 based on the community Redis 4.0 engine, compared to Redis3.x version, brought the following new function features, mainly involving the following updates:
Lazyfree mechanism, avoiding the blocking of redis-server caused by commands such as del, flushdb, flushall, rename, and improve service stability; New commands, such as MEMORY, SWAPDB; Memory performance optimization, namely active fragment reorganization.
Lazyfree Mechanism
The Lazyfree mechanism of Redis 4.0, delayed deletion of large keys, reduces the impact of deletion operations on system resources. As follows:
unlink
Before Redis 4.0, when the DEL command was executed, it only returned OK after all memory associated with the specified key was released. This behavior could lead to significant delays if the key was large (e.g., containing 10 million entries in a hash), causing other connections to wait for a long time. To maintain compatibility with existing DEL semantics while addressing this issue, Redis 4.0 introduced the unlink command. The unlink command functions identically to DEL, but instead of immediately releasing memory in the main thread, it offloads the memory release action to a background thread. This allows Redis to return a response to the client immediately, improving performance and responsiveness, especially when dealing with large data sets.
UNLINK key [key...]
flushdb/flushall
flushdb/flushall introduced new options in Redis 4.0, you can specify whether to use the Lazyfree method to empty the entire memory.
FLUSHALL [ASYNC]
FLUSHDB [ASYNC]
rename
When executing the RENAME command with the syntax rename oldkey newkey, if newkey already exists, Redis will first delete the existing newkey. This behavior can lead to the same large key deletion issue mentioned previously, as the deletion process will block until all memory associated with newkey is released, potentially causing delays if newkey is large.
New Commands
swapdb: Swap the data of two databases, after swapdb is executed, the user does not need to execute select again to see the new data.
zlexcount: For use in sorted sets, similar to zrangebylex, the difference is that zrangebylex returns member, and zlexcount is the return count of the members that meet the conditions.
memory: Redis 4.0 users can fully understand the memory state of Redis by using this command, while the previous version could only understand the limited memory information of Redis through info memory.
memory usage: The usage sub-command can view how much memory a key actually occupies inside redis.
memory stats: Memory usage details of the current Redis instance.
memory doctor: Mainly used to provide some diagnostic suggestions and discover potential problems in advance.
malloc stats & malloc purge: These two commands are used to operate jemalloc and are only effective when using jemalloc.