using UUID1 with phpcassa

2019-05-21 02:28发布

问题:

Have following CF:

create column family gr_ip2
with column_type = 'Standard' and comparator = 'TimeUUIDType(reversed=true)' ...;

then do following code:

$uuid1 = phpcassa\UUID::uuid1(null, $time);
$cf->insert("$key"  , array($uuid1 => $url) );

it works without exceptions, but CF at the end is empty.

回答1:

$uuid1 is not string, but an object. When we do

$cf->insert("$key"  , array($uuid1 => $url) );

the object is converted to string, and insert fails. phpcassa does not give exeption, but insert fails anyway.

Seems like we need to use ARRAY_FORMAT, so the object not to be "flatten" to string,

$uuid1 = phpcassa\UUID::uuid1(null, $time);

$cf->insert_format = phpcassa\ColumnFamily::ARRAY_FORMAT;

$cf->insert("$key"  , array(
      array($uuid1, $url)
) );