当前位置:网站首页>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机器学习课程评测来了!
- Docker starts MySQL and -emysql_ ROOT_ Password = my secret PW problem solving
- (1)长安链学习笔记-启动长安链
- Isomorphism + cross end, knowing applet +kbone+finclip is enough!
- Station B Big utilise mon monde pour faire un réseau neuronal convolutif, Le Cun Forward! Le foie a explosé pendant 6 mois, et un million de fois.
- 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
- MySQL数据库之JDBC编程
- A few suggestions for making rust library more beautiful! Have you learned?
- NFTScan 开发者平台推出 Pro API 商业化服务
- Can online reload system software be used safely? Test use experience to share with you
猜你喜欢
MySQL connected vscode successfully, but this error is reported
MySQL implementation of field segmentation from one line to multiple lines of example code
I've been laid off, and I'll lose money for everything. The days when I once made a monthly salary of 20000 are not coming back
Gold three silver four, don't change jobs
JS addition, deletion, modification and query of JSON array
Isomorphism + cross end, knowing applet +kbone+finclip is enough!
Entropy information entropy cross entropy
Today, I met a senior test developer from Tencent and saw the ceiling of the foundation
谁说新消费品牌大溃败?背后有人赢麻了
Detailed explanation of regular expression (regexp) in MySQL
随机推荐
Children's pajamas (Australia) as/nzs 1249:2014 handling process
为了交通安全,可以做些什么?
AI金榜题名时,MLPerf榜单的份量究竟有多重?
Huawei cloud gaussdb (for redis) unveils issue 21: using Gauss redis to achieve secondary indexing
After 3 years of testing bytecan software, I was ruthlessly dismissed in February, trying to wake up my brother who was paddling
Summary of three methods for MySQL to view table structure
不要再说微服务可以解决一切问题了
Per capita Swiss number series, Swiss number 4 generation JS reverse analysis
leetcode:236. The nearest common ancestor of binary tree
今日睡眠质量记录78分
借助这个宝藏神器,我成为全栈了
问下各位,有没有flink sql生成作业的文档啊或是案列啊知道flink cli可以建表和指定目
Knowledge * review
koa2对Json数组增删改查
每日刷题记录 (十五)
英国都在试行4天工作制了,为什么BAT还对996上瘾?
Why are some people still poor and living at the bottom of society even though they have been working hard?
Coscon'22 community convening order is coming! Open the world, invite all communities to embrace open source and open a new world~
JS addition, deletion, modification and query of JSON array
Experiment 4: installing packages from Gui