当前位置:网站首页>Redis multithreading and ACL
Redis multithreading and ACL
2022-06-26 05:59:00 【Juvenile deer】
Redis Is it a single thread
Redis The single thread mainly refers to Redis Network of IO And key value pairs are read and written by one thread , This is also Redis The main process of providing external key value storage service . but Redis Other functions of , Like persistence 、 Delete asynchronously 、 Cluster data synchronization, etc , It's actually executed by extra threads .
Redis How does a single thread handle so many concurrent client connections ?
This is it. Redis Bottom IO Structure of communication IO Multiplexing

# see redis Maximum number of connections supported , stay redis.conf Modifiable in file , # maxclients 10000 127.0.0.1:6379> CONFIG GET maxclients ##1) "maxclients" ##2) "10000"
Redis Provide multithreading support
1. redis 6.0 Provides multithreading support ,redis 6 Previous versions , Strictly speaking, it is also multithreaded , It's just a single threaded model when executing requests for user commands , There are also threads used to perform background tasks ,
such as unlink Delete Big key,rdb Persistence, etc .
redis 6.0 Provides multithreaded read and write IO, But the thread that ultimately executes user commands is still single threaded , such , There is no competition for multithreaded data , Still very efficient .
redis 6.0 Previously, thread execution mode , The following operations are executed in a thread

Redis As a single thread, why is the efficiency still so high
1: Because all its data is Memory in , All operations are memory level operations , And single thread avoids the performance loss of multi-threaded switching . It is because Redis A single thread , So be careful with Redis Instructions , For those time-consuming instructions ( such as keys), Be sure to use it carefully , Carelessness can lead to Redis Carton .( The memory response time is 100 nanosecond )
2: Non blocking I/o operation ,Redis Of IO Multiplexing :redis utilize epoll To achieve IO Multiplexing , Put connection information and events in the queue , Put it in the file event dispatcher , The event dispatcher distributes events to the event handler .
3: Using a single thread to avoid unnecessary context switching and race conditions , There is also no switching consumption caused by multiple processes or multiple threads CPU,
4,: The data structure is simple , It's also easy to manipulate data ,Redis The data structure in is specially designed ;
redis 6.0 Thread execution mode :
The multithreading model can be configured with the following parameters :
Such as :
io-threads 4 // Here it is There are three IO Threads , Another thread is main Threads ,main Threads are responsible for IO Read write and command execution operations
By default , The above configuration , There are three IO Threads , These three IO Threads only execute IO Medium write operation , in other words ,read and Command execution All by main Threads execute . Finally, multithreading writes the data back to the client .

The following parameters are enabled :
io-threads-do-reads yes // Will support IO Threads execute Reading and writing tasks .

2. client side caching
Client cache :redis 6 Provides server-side tracking key The change of , Characteristics of client cache data , This requires client implementation

The execution process is , When a client accesses a key when , The server will record key and client , After the client gets the data , Client caching , At this time , When key When interviewed again ,key Will be returned directly to , Avoid contact with redis Server interaction again , Save server resources , When data is modified by other requests , The server will actively notify the client of the failure key, The client performs local invalidation , On next request , Get the latest data again .
At present, only lettuce It is supported :
<dependency> <groupId>io.lettuce</groupId> <artifactId>lettuce-core</artifactId> <version>6.0.0.RELEASE</version> </dependency>
public static void main(String[] args) throws InterruptedException {
RedisClient redisClient = RedisClient.create("redis://192.168.109.200");
Map<String, String> clientCache = new ConcurrentHashMap<>();
StatefulRedisConnection<String, String> myself = redisClient.connect();
CacheFrontend<String, String> frontend =
ClientSideCaching.enable(CacheAccessor.forMap(clientCache),
myself,
TrackingArgs.Builder.enabled().noloop());
String key="csk";
int count = 0;
while (true){
System.out.println(frontend.get(key));
TimeUnit.SECONDS.sleep(3);
if (count++ == Integer.MAX_VALUE){
myself.close();
redisClient.shutdown();
}
}
}ACL
ACL It is the control of command access and execution permission , By default , You can execute arbitrary instructions , Compatible with previous versions
ACL There are two ways to set
1: Command mode
ACL SETUSER + Specific permission rules , adopt ACL SAVE persist
2 Yes ACL Configuration file for writing , And perform ACL LOAD Loading
ACL There are two ways to store , However, the two methods cannot be configured at the same time , Otherwise, you will directly report an error and exit the process
1.redis The configuration file : redis.conf
2.ACL The configuration file , stay redis.conf Pass through aclfile /path To configure acl Path to file
Command mode :
ACL SETUSER alice // Create a The user is called alice Users of
The user semantics created with the above command is :
1. be in off state , It is disabled , Out-of-service auth authentication
2. Cannot access any commands
3. You cannot access any key
4. No password
Above user alice It doesn't make any sense .
Create a pair of cached: The prefix has get User with Command Execution Authority , And set the password :
acl setuser alice on >pass123 ~cached:* +get auth alice pass123 set a a (error) NOPERM this user has no permissions to run the 'set' command or its subcommand get a a (error) NOPERM this user has no permissions to access one of the keys used as arguments get cached:name vvv
Above , If you access an unauthorized command , perhaps key, Will be an error ,set The command is not authorized , key a Not authorized ,
cached:name Can be verified by .
A format more in line with reading habits
ACL GETUSER alice
Add multiple access modes , The blank space to separate , Be careful , Switch other users to log in ,alice No, admin jurisdiction
ACL SETUSER alice ~objects:* ~items:* ~public:*
Constraints on type commands
ACL SETUSER alice on [email protected] [email protected] > password ~*
here [email protected]: Contains all the commands And then use [email protected] Remove in redis command table As defined in dangerous command

You can view which commands belong to a category through the following commands
acl cat // See all categories acl cat dangerous // View all dangerous command
Open subcommand
ACL SETUSER myuser -client +client|setname +client|getname
Ban client command , But open client Subcommands in the command setname and getname , You can only disable , Add subcommand after , Because new commands may be added later .
边栏推荐
- 项目中止
- 机器学习 07:PCA 及其 sklearn 源码解读
- Implementation of third-party wechat authorized login for applet
- 一段不离不弃的爱情
- numpy. exp()
- The difference between overload method and override method
- 小程序如何关联微信小程序二维码,实现二码聚合
- 【C語言】深度剖析數據在內存中的存儲
- How to associate wechat applet QR code to realize two code aggregation
- Redis underlying data structure
猜你喜欢

bingc(继承)

家庭记账程序(第一版)

On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back

Getting started with Python
![Selective search for object recognition paper notes [image object segmentation]](/img/cf/d3b08d41083f37c164b26a96b989c9.png)
Selective search for object recognition paper notes [image object segmentation]

Adapter mode
Posting - don't get lost in the ocean of Technology

小程序第三方微信授权登录的实现

【 langage c】 stockage des données d'analyse approfondie en mémoire

Consul service registration and discovery
随机推荐
SQL Server视图
one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
MySQL database-01 database overview
力扣 875. 爱吃香蕉的珂珂
Summary of the 10th provincial Blue Bridge Cup
Old love letters
RIA想法
家庭记账程序(第二版 加入了循环)
FindControl的源代码
5 minutes to learn regular expressions
Win socket programming (Mengxin initial battle)
Vs2022 offline installation package download and activation
C generic speed
Redis多线程与ACL
The most refined language interprets the event dispatcher (also known as the event scheduler)
421-二叉树(226. 翻转二叉树、101. 对称二叉树、104.二叉树的最大深度、222.完全二叉树的节点个数)
卷妹带你学jdbc---2天冲刺Day2
Matching environment of ES6
适配器模式
A new explanation of tcp/ip five layer protocol model