当前位置:网站首页>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 .
边栏推荐
- 谁说新消费品牌大溃败?背后有人赢麻了
- 士大夫哈哈哈
- 氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!
- 若依请求url中带有jsessionid的解决办法
- Modules that can be used by both the electron main process and the rendering process
- MySQL数据库之JDBC编程
- 借助这个宝藏神器,我成为全栈了
- The method of reinstalling win10 system is as simple as that
- Stop saying that microservices can solve all problems
- (DART) usage supplement
猜你喜欢
亚朵三顾 IPO
koa2对Json数组增删改查
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
吴恩达2022机器学习课程评测来了!
每日刷题记录 (十五)
英国都在试行4天工作制了,为什么BAT还对996上瘾?
mysql连接vscode成功了,但是报这个错
Up to 5million per person per year! Choose people instead of projects, focus on basic scientific research, and scientists dominate the "new cornerstone" funded by Tencent to start the application
None of the strongest kings in the monitoring industry!
Master binary tree in one article
随机推荐
Huawei cloud gaussdb (for redis) unveils issue 21: using Gauss redis to achieve secondary indexing
Use mitmproxy to cache 360 degree panoramic web pages offline
AI金榜题名时,MLPerf榜单的份量究竟有多重?
None of the strongest kings in the monitoring industry!
mysql连接vscode成功了,但是报这个错
基础图表解读“东方甄选”爆火出圈数据
TDengine 社区问题双周精选 | 第二期
Docker starts MySQL and -emysql_ ROOT_ Password = my secret PW problem solving
Spark Tuning (II): UDF reduces joins and judgments
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
Can online reload system software be used safely? Test use experience to share with you
每年 2000 亿投资进入芯片领域,「中国芯」创投正蓬勃
为了交通安全,可以做些什么?
AcWing 4299. Delete point
Gold three silver four, don't change jobs
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
若依请求url中带有jsessionid的解决办法
达晨史上最大单笔投资,今天IPO了
Master binary tree in one article
There are only two TXT cells in the ArrayExpress database. Can you only download the sequencing run matrix from line to ENA?