当前位置:网站首页>Design of short chain
Design of short chain
2022-07-06 23:34:00 【OoZzzy】
At present, in many scenarios , All need short chains , Especially involving some URL The logic of distribution . I used to be a pony AI Class business , The link sent by sales through SMS is a short chain . Why need a short chain ? Consider a URL There are path、query Equal parameter , Various parameters are spliced together to form a long string .
List of articles
1. Short chain composition
agreement + domain name + path, The agreement can be directly ignored . Domain name is a must ( crap ), And short enough , Otherwise, it will become a long short chain ( It's silly ). Last path Is the key , It seems to be a 6 A string of characters , And the range of characters is upper and lower case letters + Numbers .
2.Path Generation
2.1 The hash algorithm
Path One of the ways is to calculate by hash algorithm . Common hash functions are MD5、SHA1 And other common cryptographic hash algorithms , Also have HighwayHash、MurmurHash And other non encrypted hash functions . With MurmurHash For example , It has been iterated to MurmurHash 3, Capable of producing 32bit and 128 bit Hash value of , And for those with strong regularity key, The characteristics of random distribution are very good .
However, hash conflicts are uncontrollable , Although we have N A way to resolve hash conflicts , But it will increase the overall complexity of the whole system .
2.2 Self increasing ID
You can also maintain one ID Auto generator , For each long chain generation 1、2、3 And so on , Then save the mapping of long chain and serial number in the database , Then get such as https://fake.short/1、https://fake.short/2 Equal short chain . Considering that a single machine is easy to cause a single point of failure , So it is generally distributed ID generator .
- Mysql
- SnowFlake
- UidGenerator Baidu
- Leaf Meituan
2.3 Further shortening
If we get 『1536389934』 This serial number , It still looks a little long , If you want to further shorten , You can convert decimal numbers into 62 Hexadecimal number . Then you get a shorter number than the original ID 了 .
Why use 62 Hexadecimal conversion ?
62 Base conversion is because 62 After binary conversion, only numbers are included + A lowercase letter + Capital . and 64 The base conversion will contain /,+ Such symbols ( It's not normal URL The characters of )encodeURIComponent(‘+’) => %xx
10 Turn into the system 62 Hexadecimal can shorten characters , If we want to 6 Bit words , There has been a 560 Billion combinations .
边栏推荐
- The problem of ASP reading Oracle Database
- Can async i/o be implemented by UDF operator and then called by SQL API? At present, it seems that only datastre can be seen
- A few suggestions for making rust library more beautiful! Have you learned?
- Knowledge * review
- A novice asks a question. I am now deployed on a single machine. I submitted an SQL job and it runs normally. If I restart the service job, it will disappear and I will have to
- Gold three silver four, don't change jobs
- Use mitmproxy to cache 360 degree panoramic web pages offline
- The best sister won the big factory offer of 8 test posts at one go, which made me very proud
- MySQL implementation of field segmentation from one line to multiple lines of example code
- Gradle知识概括
猜你喜欢

After 3 years of testing bytecan software, I was ruthlessly dismissed in February, trying to wake up my brother who was paddling

Knowledge * review

每年 2000 亿投资进入芯片领域,「中国芯」创投正蓬勃

氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!

Today's sleep quality record 78 points

NFTScan 开发者平台推出 Pro API 商业化服务
![[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code](/img/4c/5d867437aac5faa299817e187602e1.png)
[unmanned aerial vehicle] multi unmanned cooperative task allocation program platform, including Matlab code

吴恩达2022机器学习课程评测来了!

亚朵三顾 IPO

传统企业要为 Web3 和去中心化做的 11 个准备
随机推荐
请问oracle-cdc用JsonDebeziumDeserializationSchema反序列化
AI金榜题名时,MLPerf榜单的份量究竟有多重?
Experiment 4: installing packages from Gui
使用MitmProxy离线缓存360度全景网页
The problem of ASP reading Oracle Database
【OFDM通信】基于深度学习的OFDM系统信号检测附matlab代码
Is the more additives in food, the less safe it is?
What can be done for traffic safety?
设计一个抢红包系统
吴恩达2022机器学习课程评测来了!
Please help xampp to do sqlilab is a black
英国都在试行4天工作制了,为什么BAT还对996上瘾?
How much does the mlperf list weigh when AI is named?
Gold three silver four, don't change jobs
实现多彩线条摆出心形
若依请求url中带有jsessionid的解决办法
What does security capability mean? What are the protection capabilities of different levels of ISO?
Today's sleep quality record 78 points
A few suggestions for making rust library more beautiful! Have you learned?
安全保护能力是什么意思?等保不同级别保护能力分别是怎样?