首页 > 饭否的一条text的url怎么生成?

饭否的一条text的url怎么生成?

fanfou.com/statuses/xMvsU3SMr8s

这是个典型的url,我想知道后面的随意的字母串是怎么生成的?存在数据库里?生成时是不是还要查询数据库是否有重复?


参考weibo的 62进制


我猜测也许是后台用纯数字做的确保唯一性,然后再通过一定算法,展现为:xMvsU3SMr8s,其实在后台数据表中,有可能是有一个纯数字的ID字段的。


Twitter的Tweet ID包含时间戳、服务器号码、序列号。

https://dev.twitter.com/docs/twitter-ids-json-and-snowflake

So what is Snowflake?

Snowflake is a service we will be using to generate unique Tweet IDs. These Tweet IDs are unique 64bit unsigned integers, which, instead of being sequential like the current IDs, are based on time. The full ID is composed of a timestamp, a worker number, and a sequence number.

Tweet ID可以直接按数字排序,所以说时间戳应当安排在最前面的部分,因而各服务器的时钟必须保持同步。

饭否的ID算法没有公开,应该也是类似的思路。

【热门文章】
【热门文章】