"" + 237498237498273908472390847239084710298374901823749081237409273492374098273904872398471298374
> '2.3749823749827392e+92'
我以一种美妙而神秘的方式计算ID:
time = new Date().getTime()
pid = process.pid
host = 0; (host +=s.charCodeAt(0) for s in os.hostname())
counter = MIPS.unique_id()
"#{host}#{pid}#{time}#{counter}"
很不幸,在某个地方ID(例如11207648813339434616800
)出现了问题。不幸的是,这意味着它们有时会变成1.1207648813339434e+22
。
更新:
看起来这是redis的“错误/特性”。从未想到过这一点。
# Bug with Big Numbers on zadd
redis = require 'redis'
r = redis.createClient()
r.zadd 'zset', '342490809809999998098', 'key', ->
r.zscore 'zset', 'key', (_, results) ->
console.log typeof results # string
console.log results # 3.4249080981000002e+20
% 1e18
怎么样? - Peter C