当前位置:网站首页>Linux server development, redis protocol and asynchronous mode

Linux server development, redis protocol and asynchronous mode

2022-07-07 07:54:00 Tuen Mun pheasant calls me chicken

Recommend a free open course of zero sound College , Personally, I think the teacher spoke well , Share with you :Linux,Nginx,ZeroMQ,MySQL,Redis,fastdfs,MongoDB,ZK, Streaming media ,CDN,P2P,K8S,Docker,TCP/IP, coroutines ,DPDK Etc , Learn now

1.redis The network layer of

single reactor Model
 Insert picture description here
 Insert picture description here

2.redis Of pipeline

redis It's a request response .pipeline Is a client behavior , It can send multiple commands at once , Back together , At least one round-trip time is saved . take pipeline Add transaction in
lua Multiple statements can be written in a script , And you can have your own logic ,lua The form ability of is relatively strong and atomic . because lua A script is just a command ,redis A single thread , So nature has atomicity .
 Insert picture description here
client script load xxx.lua Send to server , Generate 40 Bit string as a flag script , Reduce network transmission

  • A: When you reach a certain state, you can return to the original state .redis It's not atomic , Rollback is not supported .
  • C: Constraints are to remain intact ,redis There is no consistency in the traditional sense , For example, add money and reduce money , There are successes and failures .
  • I: Single thread execution , All have isolation .
  • D: Four persistence strategies .redis It's persistent .

3.redis The business of multi exec lua

adopt MULTI and EXEC The command defines the scope of the transaction . adopt wacth Command lock key, If key Automatically cancel the transaction when changes occur . Usually use lua Scripts handle transactions . It's not transactional , Atomicity , The main goal is to reduce the time of network transmission .

4.redis pub/sub

5. Asynchronous connection

skynet Adopt asynchronous connection .

Four aspects to be realized in the future

  • Single threaded reactor
  • Multithreading reactor, One in charge listen,8 Threads are responsible for operating the network IO
  • Ctrip eliminates callback ,go Language understanding is more profound
  • Implement a third-party agreement ,redis,MySql,etcd
原网站

版权声明
本文为[Tuen Mun pheasant calls me chicken]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130647575363.html