コード例 #1
0
ファイル: range_test.php プロジェクト: atomicjets/phpcassa
/*
 * Instead to do some crazy token calculation,
 * we can crease an array with tokens that are interested for us.
 */
$tokens = array(0 => "0", 1 => "21267647932558653966460912964485513216", 2 => "42535295865117307932921825928971026432", 3 => "63802943797675961899382738893456539648", 4 => "85070591730234615865843651857942052864", 5 => "106338239662793269832304564822427566080", 6 => "127605887595351923798765477786913079296", 7 => "148873535527910577765226390751398592512", 8 => "170141183460469231731687303715884105727");
/*
 * instead of Lucas number, you can specify token outside the ring,
 * however it will not work if you specify 0 (zero) as end of the ring.
 * 			8 => "200000000000000000000000000000000000000",
 */
// Connect to Cassandra and create an instance of the CF.
$pool = new ConnectionPool('test', array('127.0.0.1'));
$cf = new ColumnFamily($pool, 'a');
$column_to_show = "id";
// Collect the begin and end token from command line...
$begin_token = @$argv[1] ? $argv[1] : 0;
$end_token = @$argv[2] ? $argv[2] : 8;
// Collect the begin and end token from query_string...
if (@$_REQUEST["begin_token"]) {
    $begin_token = $_REQUEST["begin_token"];
}
if (@$_REQUEST["end_token"]) {
    $end_token = $_REQUEST["end_token"];
}
// Use <pre> it for web output
echo "<pre>\n\n";
// Use the iterator...
$br = 0;
foreach ($cf->get_range_by_token($tokens[$begin_token], $tokens[$end_token], 1000) as $x) {
    printf("No. %10d : Data: %s\n", ++$br, @$x[$column_to_show]);
}