当前位置:网站首页>Redis6.0 new features (Part 2)

Redis6.0 new features (Part 2)

2022-06-22 02:56:00 Java interview 365

Redis6.0 New characteristics

Multithreading networks IO

When I saw this, my first reaction was , what ! Isn't it faster for a single thread ? To 6.0 Just fooling around ? Before Redis That's what the author said

because Redis Is a memory based operation ,CPU No Redis Bottleneck ,Redis The most likely bottleneck is the size of machine memory or network bandwidth . Since a single thread is easy to implement , and CPU Not a bottleneck , So it's natural to adopt a single thread solution

Let's think about a question first ,Redis What does single thread mean in ?

== The Internet IO And read / write operations of key value pairs ==, That is to say RDB File generation ,AOF File rewriting , Data deletion and so on are all asynchronous operations .

So why 6.0 The network needs to be IO Change to multithreading ?

Because with the improvement of network hardware ,Redis Performance bottlenecks may occur on the network IO On , That is to say, the processing speed of a single thread cannot keep up with that of the underlying network hardware .

6.0 Previous networks IO Handle

Here's a simple one RedisIO Processing order , Of course Redis Add multiplexing IO After the model , Relatively speaking, it is more complicated , Multiplexing will not be discussed here for the time being IO Model .

6.0 After the network IO Handle

6.0 After that, we mainly focus on the above two networks IO To optimize , Add multithreading , The process diagram is as follows

The logic of the process diagram may not be shown , So it can be seen in combination with the following flow chart

stay Redis6.0 Multithreading will not be enabled by default , We can do it in redis.conf The following commands are configured in the file , Enable multithreading

###  Enable multithreading 
io-threads-do-reads yes

When using multithreading, you also need to pay attention to a configuration

io-threads  Number of threads 

Redis The official pointed out that , Use multithreaded scenarios CPU The number of cores must reach 4 Supranuclear , If CPU yes 4 The number of threads recommended by the core official is set to 2-3, If CPU Auditing for 8 nucleus , Then the official recommended configuration 6 individual IO Threads , If you use more than 8 Threads will not significantly improve performance , in other words The number of threads should be less than that of the instance machine CPU Number of cores .

Fine grained permission control ACL

stay Redis6.0 Previously, we wanted to prohibit the execution of some commands in production, such as (KEYS、FLUSHDB、FLUSHALL wait ), Our solution can only be to adopt rename-command Command to rename a particular command , Avoid misoperation , How to achieve it ?

6.0 Previous command restrictions

find redis.conf The configuration file , We can do it in SECURITY Under module , Add the following configuration

### rename-command  Old orders   New command   The following order is to KEYS Rename the command to TEST
rename-command KEYS TEST

Add the configuration , Restart the service after saving successfully

###  The original command is not recognized , The new command succeeded 
127.0.0.1:6379> keys *
(error) ERR unknown command `keys`, with args beginning with: `*`,
127.0.0.1:6379> test *
1) "name"
2) "age"

6.0 After that, permission control

Redis6.0 After that, the concept of user is mainly added , This is not available in the previous version , Depending on the user, you can bind permissions

###  Create a test user , take test The user's password is set to test
127.0.0.1:6379> ACL SETUSER test on >test
OK

Enable or disable commands

###  user test Enable hash Command and string command ( You can also specify the prefix of the operation key value ~name*)
ACL SETUSER test [email protected] [email protected]

 Insert picture description here

Code demonstration

127.0.0.1:6379> keys *
1) "name2"
2) "age"
3) "name1"
4) "name"
###  establish test user , Password plaintext is set to test, Operation only allowed name Key value at the beginning , All commands can be operated 
127.0.0.1:6379> ACL SETUSER test on >test ~name* [email protected]
OK
###  Authority verification , land test
127.0.0.1:6379> auth test test
OK
127.0.0.1:6379> get name
"2"
### test User get non name The key value at the beginning failed 
127.0.0.1:6379> get age
(error) NOPERM this user has no permissions to access one of the keys used as arguments
127.0.0.1:6379> set name 2
OK
127.0.0.1:6379> set age 2
(error) NOPERM this user has no permissions to access one of the keys used as arguments
127.0.0.1:6379>
127.0.0.1:6379> DECR age
(error) NOPERM this user has no permissions to access one of the keys used as arguments
原网站

版权声明
本文为[Java interview 365]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220253293304.html