当前位置:网站首页>Redis6.0新特性(下)
Redis6.0新特性(下)
2022-06-22 02:53:00 【Java面试365】
Redis6.0新特性
多线程处理网络IO
当时看到这个其实第一反应就是,啥!不是说单线程更快吗?到6.0就瞎搞了?之前Redis作者不是这么说的吗
因为Redis是基于内存的操作,CPU不是Redis的瓶颈,Redis的瓶颈最有可能是机器内存的大小或者网络带宽。既然单线程容易实现,而且CPU不会成为瓶颈,那就顺理成章地采用单线程的方案了
我们先思考一个问题,Redis中的单线程是指什么呢?
==网络IO以及键值对的读写操作==,也就是RDB文件生成,AOF文件重写,数据删除等等其实都是异步操作。
那么为什么6.0需要将网络IO改为多线程呢?
因为随着网络硬件的提升,Redis的性能瓶颈可能会出现在网络IO上,也就是说单个线程处理网络的速度跟不上底层网络硬件的处理速度。
6.0之前的网络IO处理
下面是一个简单RedisIO处理顺序,当然Redis加入多路复用IO模型后,相对而言复杂点,这里暂时不讨论多路复用IO模型。

6.0之后的网络IO处理
6.0之后主要是针对上面的两处网络IO进行优化,加入多线程处理,处理过程图如下所示

处理过程图逻辑可能没有表现出来,所以可以结合下面的流程图看即可

在Redis6.0中默认是不会开启多线程的,我们可以在redis.conf文件中配置如下命令,开启多线程
### 开启多线程
io-threads-do-reads yes
在使用多线程时还需要注意一个配置
io-threads 线程数
Redis官方指出,使用多线程场景CPU的核数必须达到4核以上,如果CPU是4核心官方建议线程数设置为2-3,如果CPU核数为8核,那么官方建议配置6个IO线程,如果使用超过8个线程那么对性能的显著提升就不大了,也就是说线程数需要小于实例所在机器的CPU核个数。
细粒度权限控制ACL
在Redis6.0之前我们想要在生产上禁止一些命令的执行如(KEYS、FLUSHDB、FLUSHALL等等),我们的办法只能是采用rename-command命令给特殊的命令重命名,避免误操作,如何实现呢?
6.0之前的命令限制
找到redis.conf配置文件,我们可以在SECURITY模块下面,添加如下配置
### rename-command 旧命令 新命令 下面的命令就是将KEYS命令重命名为TEST
rename-command KEYS TEST
添加配置,保存成功后重启服务
### 采用原有命令不识别,新命令成功
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之后权限控制
Redis6.0之后主要添加了用户的概念,这是之前的版本没有的,依靠用户可以进行权限绑定
### 创建一个test用户,将test用户的密码设置为test
127.0.0.1:6379> ACL SETUSER test on >test
OK
启用或者禁用命令
### 用户test启用hash命令以及string命令(也可以指定操作键值的前缀~name*)
ACL SETUSER test [email protected] [email protected]

代码演示
127.0.0.1:6379> keys *
1) "name2"
2) "age"
3) "name1"
4) "name"
### 创建test用户,密码明文设置为test,只允许操作name开头的键值,可以操作所有命令
127.0.0.1:6379> ACL SETUSER test on >test ~name* [email protected]
OK
### 权限验证,登陆test
127.0.0.1:6379> auth test test
OK
127.0.0.1:6379> get name
"2"
### test用户获取非name开头的键值失败
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
边栏推荐
- Day21qt mouse event 2021-11-01
- Game Jam开发周期
- [8. One dimensional prefix and]
- 【4. 高精度加法】
- ModuleNotFoundError: No module named ‘torchvision. datasets‘; ‘ torchvision‘ is not a package
- [2. merge sort]
- Starting WDA with tidevice
- Dernière publication: neo4j Graph Data Science GDS 2.0 et aurads ga
- Right and left vertical time axis with serial number
- Li Kou today's question 1108 IP address invalidation
猜你喜欢
![[3. binary integer and floating point number]](/img/82/6c3ef250b90d875cddaebc5bd4a4b8.png)
[3. binary integer and floating point number]

web框架概述与程序开发

Markdown is proficient in Elementary Grammar and is compatible with marktext

关于PMP考试,你想知道的知识都在这里了

PMP备考相关敏捷知识
![Comprehensive interpretation by enterprise reviewers: enterprise growth of [State Grid] China Power Finance Co., Ltd](/img/4e/345ceb4e91aae844d7ab53ad3fd988.png)
Comprehensive interpretation by enterprise reviewers: enterprise growth of [State Grid] China Power Finance Co., Ltd

Dernière publication: neo4j Graph Data Science GDS 2.0 et aurads ga

An article thoroughly learns to draw data flow diagrams

【4. 高精度加法】

Pytorch visualization
随机推荐
The brand, products and services are working together. What will Dongfeng Nissan do next?
Automated tools - monitoring file changes
GraphConnect 2022 大会的产品发布一览
Day16QtQLabel2021-10-22
Day17QtQLcdNumber2021-10-22
Using open source software to save an enterprise level map data platform solution
Relative references must start with either “/“, “./“, or “../“.
Day18qt signal and slot 2021-10-29
Anaconda historical version download
Using neo4j sandbox to learn neo4j graph data science GDS
Using hook based on xposed framework
Classic case of JS operation node (three-level linkage)
import和require在浏览器和node环境下的实现差异
Extending kubernetes API with CRD
Day12QFile2021-09-27
HarmonyOS鸿蒙使用ORM Bee访问数据库实例
Programming of pytorch interface
C mapster object mapper learning
[3. binary integer and floating point number]
[4. high precision addition]