当前位置:网站首页>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 .
边栏推荐
- numpy.exp()
- tf.nn.top_k()
- String类学习
- How to associate wechat applet QR code to realize two code aggregation
- Source code of findcontrol
- 自定义WebSerivce作为代理解决SilverLight跨域调用WebService问题
- Redis多线程与ACL
- The most refined language interprets the event dispatcher (also known as the event scheduler)
- Given two corresponding point sets AB, how to estimate the parameters of the specified transformation matrix R?
- 5分钟包你学会正则表达式
猜你喜欢
![Selective search for object recognition paper notes [image object segmentation]](/img/cf/d3b08d41083f37c164b26a96b989c9.png)
Selective search for object recognition paper notes [image object segmentation]

C generic speed

类和对象的学习

Younger sister Juan takes you to learn JDBC -- two days' Sprint Day2

家庭记账程序(第二版 加入了循环)

MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications

REUSE_ALV_GRID_DISPLAY 事件实现(DATA_CHANGED)

Spark source code analysis (I): RDD collection data - partition data allocation

5 minutes to learn regular expressions

pytorch(环境、tensorboard、transforms、torchvision、dataloader)
随机推荐
Machine learning 05: nonlinear support vector machines
ES6的搭配环境
Day4 branch and loop
numpy.random.choice
The purpose of writing programs is to solve problems
类和对象的学习
Sql查询时间段内容
Summary of JVM interview focus (II) -- garbage collector (GC) and memory allocation strategy
FindControl的源代码
Describe an experiment of Kali ARP in LAN
BOM document
Upgrading technology to art
tf.nn.top_k()
Record how to modify the control across threads
【 langage c】 stockage des données d'analyse approfondie en mémoire
SQL Server视图
睛天霹雳的消息
numpy. log
SSH keygen specifies the path
Force buckle 875 Coco, who likes bananas