当前位置:网站首页>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 .
边栏推荐
猜你喜欢
从新东方直播来探究下小程序音视频通话及互动直播

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

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

Status mode, body can change at will

小程序如何关联微信小程序二维码,实现二码聚合

Ribbon load balancing service call

Household accounting procedures (First Edition)
![Operator priority, associativity, and whether to control the evaluation order [detailed explanation]](/img/c3/a646a7c7cb82e00746923f7b023058.jpg)
Operator priority, associativity, and whether to control the evaluation order [detailed explanation]

Detailed explanation of serial port communication principle 232, 422, 485

Test depends on abstraction and does not depend on concrete
随机推荐
Machine learning 07: Interpretation of PCA and its sklearn source code
Matching environment of ES6
Describe an experiment of Kali ARP in LAN
06. talk about the difference and coding between -is and = = again
kolla-ansible部署openstack yoga版本
转帖——不要迷失在技术的海洋中
DOM document
Project suspension
冒泡排序(Bubble Sort)
Getting started with Python
Household accounting procedures (First Edition)
COW读写复制机制在Linux,Redis ,文件系统中的应用
one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
Pytorch (environment, tensorboard, transforms, torchvision, dataloader)
421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
Kolla ansible deploy openstack Yoga version
卷妹带你学jdbc---2天冲刺Day2
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
Explore small program audio and video calls and interactive live broadcast from New Oriental live broadcast
tf.nn.top_k()