php – UUID cassandra排序?

假设我有一个用户列系列,为特定客户端预设了唯一的键名

<?php 
uniqid ("serverA");//generate something like; serverA4b3403665fea6
?>

我可以通过二级索引等选择它们:(生日例子来自phpcassa)

$column_family = new ColumnFamily($conn, 'Indexed1');
$index_exp = CassandraUtil::create_index_expression('birthdate', 1984);
$index_clause = CassandraUtil::create_index_clause(array($index_exp));
$rows = $column_family->get_indexed_slices($index_clause);
// returns an Iterator over:
//    array('winston smith' => array('birthdate' => 1984))

foreach($rows as $key => $columns) {
    // Do stuff with $key and $columns
    Print_r($columns)
}

但是我只希望查询每页有30个最新添加的用户(创建的密钥)和多页面布局,每个页面显示较旧的密钥

我目前发现的唯一选择是使用来自phpcassa的uuid

uuid1() generates a UUID based on the current time and the MAC
address of the machine.

  • Pros: Useful if you want to be able to sort your UUIDs by creation time.
  • Cons: Potential privacy leakage since it reveals which computer it was generated on and at what time.
  • Collisions possible: If two UUIDs are generated at the exact same time (within 100 ns) on the same machine. (Or a few other unlikely
    marginal cases.)

uuid2() doesn’t seem to be used anymore.

uuid3() generates a UUID by taking an MD5 hash of an arbitrary name
that you choose within some namespace (e.g. URL, domain name, etc).

  • Pros: Provides a nice way of assigning blocks of UUIDs to different namespaces. Easy to reproduce the UUID from the name.
  • Cons: If you have a unique name already, why do you need a UUID?
  • Collisions possible: If you reuse a name within a namespace, or if there is a hash collision.

uuid4() generates a completely random UUID.

  • Pros: No privacy concerns. Don’t have to generate unique names.
  • Cons: No structure to UUIDs.
  • Collisions possible: If you use a bad random number generator, reuse a random seed, or are very, very unlucky.

uuid5() is the same as uuid3(), except using a SHA-1 hash instead
of MD5. Officially preferred over uuid3().

但这意味着我必须重写一些部分获得碰撞的可能性.

我有没有想到的智能黑客?

解决方法:

首先,关于UUID,如果您计划使用uuid1()或uuid4(),则不需要担心冲突(这些是唯一真正被使用的).这种事件的概率是天文数字低.别担心.

为了获得最近添加的30个密钥(以及分页功能),您真正在谈论时间序列数据.这是一个很好的intro to timeseries with Cassandra.您可以使用时间戳或v1 UUID作为列名称,使用唯一键作为列值.如果您选择将v1 UUID用于唯一键,则可以直接将它们放在列名中.那时你只是处理Cassandra中的正常时间序列数据和分页.

上一篇:c# – Cassandra System.OutOfMemoryException,它是一个Thrift错误吗?


下一篇:ubuntu系统(华硕笔记本)屏幕亮度用Fn控制的调节设置