About Redis 4.0 new features

Source: Internet
Author: User
Tags lua memory usage redis versions redis cluster redis labs

Antirez, the author of Redis, released the first RC version of Redis 4.0 in a blog post three days ago through the blogger candidate of Redis 4.0 was out, which he said in a blog post, because the new version of the There have been a number of changes in Redis, so he decided to jump to the 4.0 version from the original 3.x version to highlight the change in this update.

This article will make a brief introduction to the major new features of Redis 4.0, so that we'll get to know the main content of this update.

The biggest change in Redis 4.0 is the addition of a modular system that allows users to extend and implement the functionality that Redis itself does not have through the code they write, using the Antirez blog, "Redis Loadable Module System ": http://antirez.com/news/106

Because the module system is implemented through a high-level API, it is completely separate from the Redis kernel itself and does not interfere with each other, so users can enable this function if necessary, the following is the module loading method documented in redis.conf:

################################## MODULES #####################################

# Load MODULES at startup. If the server is not a able to load modules
# it'll abort. It is possible to use multiple loadmodule directives.
#
# # # # loadmodule/path/to/my_module.so
# loadmodule/path/to/other_module.so

There are already people using this feature to develop a variety of modules, such as Redis Labs developed some modules can be seen in http://redismodules.com, in addition to Antirez also use this feature developed a neural network module: https:// Github.com/antirez/neural-redis

The modular functionality allows the user to use Redis as an infrastructure and build more features on it, creating a myriad of new possibilities for Redis.

The new version of the PSYNC command addresses some of the less-than-optimized versions of Redis at the time of replication: in older versions of Redis, if one has become a new primary node from the server after FAILOVER, the other slave nodes must replicate the new master when replicating. In Redis 4.0, when the new master and slave servers handle this situation, partial replication is used where conditions permit. In the old version of Redis, if a slave server restarts, then it must be re-replicated with the primary server, and in Redis 4.0, the master and slave will use partial replication as long as the condition permits.

Newly added last frequently used cache eviction strategy, see Antirez's blog post "Random notes on improving the Redis LRU algorithm": http://antirez.com /news/109

In addition, Redis 4.0 also optimizes existing cache eviction strategies to make them more robust, efficient, fast, and accurate. non-blocking DEL, flushdb, and Flushall

Before Redis 4.0, users could block a server by using the DEL command to delete larger keys, or when using FLUSHDB and Flushall to delete a database that contains a large number of keys.

To address these issues, Redis 4.0 adds a new UNLINK command, which is an asynchronous version of the DEL command that can be executed in a background thread to remove the specified key, thereby avoiding server blocking as much as possible:

redis> UNLINK Fruits
(integer) 1

For some historical reasons, the DEL command to perform a synchronous delete operation will continue to persist.

In addition, the two commands for Flushdb and Flushall in Redis 4.0 are newly added with the ASYNC option, and a database delete operation with this option will be performed in a background thread:

redis> flushdb Async
OK

redis> flushall async
OK

Another modification to the database commands by Redis 4.0 is the addition of the swapdb command, which swaps the specified two databases: for example, by executing a command swapdb 0 1, we can turn the original database 0 into database 1, and the original database 1 becomes Database 0.

Here is an example of using swapdb:

Redis> set Your_Name "Huangz"  --set a key
OK

redis> GET your_name
"

huangz" in database 0 redis> SWAPDB 0 1  --interchange database 0 and database 1
OK

redis> GET your_name  --Now the database 0 has no previously set keys
(nil)

redis> S Elect 1  --Switch to database 1
OK

redis[1]> GET your_name  --the key previously set in database 0 can now be found in database 1
"Huangz"                 - -proof that two databases have been interchanged
hybrid rdb-aof Persistence format

Redis 4.0 has a new RDB-AOF hybrid persistence format, an optional feature that, after this feature is turned on, the AOF rewrite file will contain both the RDB format content and the AOF format content, where the RDB format content is used to record existing data, and AOF Formatted memory is used to record data that has changed recently, so that Redis can simultaneously have the benefits of both RDB persistence and AOF persistence--the ability to quickly generate rewrite files and quickly load data in the event of a problem.

This feature can be turned on using the aof-use-rdb-preamble option, which is documented in the redis.conf file:

# when rewriting the AOF file, Redis was able to use an RDB preamble in the
# AOF file for faster rewrites and Recoveri Es. When this option was turned
# on the rewritten AOF file is composed of the different stanzas:
#
#   [RDB file  ][aof tail]
#
# When loading Redis recognizes, the AOF file starts with the "Redis"
# string and loads the Prefixed RDB file, and continues loading the AOF
# tail.
#
currently turned off by default in order to avoid
the surprise # of a format change, but would at SOM E point is used as the default.
Aof-use-rdb-preamble No

A new memory command has been added, which can be used to inspect memory usage and to perform appropriate management operations on the RAM:

Redis> memory help
1) "Memory usage <key> [SAMPLES <count>]-Estimate MEMORY usage of key"
2) "MEM ORY STATS                         -Show Memory usage Details "
3)" Memory PURGE                         -Ask The allocator to release memory "
4)" Memory Malloc-stats                  -Show Allocator Internal STATS "

With the memory usage subcommand, you can estimate the amount of RAM needed to store a given key:

redis> SET msg "Hello World"
ok

redis> sadd fruits Apple Banana cherry
(integer) 3

redis> MEMORY USAGE msg
(integer)

redis> MEMORY USAGE Fruits
(integer) 375

Use the memory STATS subcommand to see the current usage of your 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 "
(integer) 0
)" Clients.normal "
(integer) 49614
)" Aof.buffer "
14 ) (integer) 0
) "db.0"
1) "Overhead.hashtable.main"
    2) (integer)
    3) " Overhead.hashtable.expires "
    4) (integer) [
overhead.total]
(integer) 1012950
19)" Keys.count
(integer) 5
) "Keys.bytes-per-key"
(integer) 10294
) "Dataset.bytes"
24) (integer) 1562) "
dataset.percentage" ("
3.0346596240997314") "
peak.percentage"
28) " 100.00315093994141 "
Fragmentation"
30) "2.1193723678588867"

Using the memory PURGE subcommand can require the allocator to release more memory:

redis> MEMORY PURGE
OK

Use the MEMORY malloc-stats subcommand to show the internal status of the allocator:

redis> MEMORY malloc-stats STATS not supported for the current
allocator
compatible with NAT and Docker

The Redis 4.0 will be compatible with NAT and Docker, and the specific usage method is documented in redis.conf:

########################## CLUSTER Docker/nat Support ######################## # in certain deployments, Redis CLUSTER n  Odes address discovery fails, because # addresses be nat-ted or because ports is forwarded (the typical case is # Docker
and other containers).  # # In order-make Redis Cluster working-such environments, a static # configuration where each node known it public Address is needed. The # following-used for this scope, and is: # # # * CLUSTER-ANNOUNCE-IP # * Cluster-announce-port # * Clus Ter-announce-bus-port # Each instruct the node on its address, client port, and cluster message # Bus port.  The information is then published in the header of the bus packets # So, other nodes'll be able to correctly map the
Address of the node # publishing the information.
# # If The above options is not used, the normal Redis Cluster auto-detection # would be used instead. # # Note that when remapped, the bus port is not being at the fixed offset of # CLients Port + 10000, so can specify any ports and Bus-port depending # on how they get remapped.
If The Bus-port is not set, a fixed offset of # 10000 would be used as usually. # # # # # # # # # # # # # # # # # Example # cluster-announce-ip 10.1.1.5 # 6379 6380
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.