ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

php – UUID cassandra排序?

2019-06-30 12:19:08  阅读:269  来源: 互联网

标签:php uuid cassandra thrift phpcassa


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

<?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中的正常时间序列数据和分页.

标签:php,uuid,cassandra,thrift,phpcassa
来源: https://codeday.me/bug/20190630/1336311.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有