如何在 Java/Scala 中生成 TimeUUID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24952066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate TimeUUID in Java/Scala
提问by Avis
Does anyone know how to generate TimeBased UUIDs in Java/Scala?
有谁知道如何在 Java/Scala 中生成基于时间的 UUID?
Here is the column family:
这是列族:
CREATE table col(ts timeuuid)
I'm using Cassandra 1.2.4
我正在使用 Cassandra 1.2.4
Appreciate your help!
感谢你的帮助!
采纳答案by mikea
Cassandra has UUIDGen for generating Timeuuids. The source for this is here:
Cassandra 有用于生成 Timeuuid 的 UUIDGen。这个的来源在这里:
回答by Govind Singh
i am using the same way for cassandra cli, and for column name i am using
我对 cassandra cli 使用相同的方式,对于我正在使用的列名
System.currentTimeMillis().toString
scala> val timestamp = System.currentTimeMillis().toString
timestamp: String = 1406279679674
UPDATE
更新
mainly it depends on your row key if rowKey is your userId
or something, then there is no chance of submission of duplicate record in miliseconds but if you think it can be repeat then use
主要取决于您的行键,如果 rowKey 是您的userId
或其他东西,则没有机会在毫秒内提交重复记录但如果您认为它可以重复然后使用
val timestamp = com.eaio.uuid.UUIDGen.newTime().toString