1

我是 casssandra 的新手,想从 CloumnFamily 获取所有行键值。假设我有 User CoulmnFamily 看起来像这样

list User

RowKey: amit
=> (column=fullname, value=amitdubey, timestamp=1381832571947000)
-------------------
RowKey: jax1
=> (column=fullname, value=jagveer1, timestamp=1381655141564000)
-------------------
RowKey: jax2
=> (column=fullname, value=amitdubey, timestamp=1381832571947000)
-------------------
RowKey: jax3
=> (column=fullname, value=jagveer3, timestamp=1381655141564000)
-------------------

我正在寻找示例代码来检索家庭的所有 keyrows 值。

像这样的东西:

amit
jax1
jax2
jax3

我的 Cassandra 版本是 1.1 感谢任何帮助

4

1 回答 1

2

您只需在 hector 客户端中使用 RangeSlicesQuery 即可。

RangeSlicesQuery<String, String, String> rangeSlicesQuery =
            HFactory.createRangeSlicesQuery(keyspace, ss, ss, ss)
                    .setColumnFamily("User")
                    .setRange(null, null, false, rowCount)
                    .setRowCount(rowCount)
                    .setReturnKeysOnly();

    String lastKey = null;

    while (true) {
        rangeSlicesQuery.setKeys(lastKey, null);

        QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
        OrderedRows<String, String, String> rows = result.get();
        Iterator<Row<String, String, String>> rowsIterator = rows.iterator();

        /**
         * we'll skip this first one, since it is the same as the last one from previous time we executed.
         */
        if (lastKey != null && rowsIterator != null) {
            rowsIterator.next();
        }
        while (rowsIterator.hasNext()) {
            Row<String, String, String> row = rowsIterator.next();
            lastKey = row.getKey();

            System.out.println(lastkey);
        }

        if (rows.getCount() < rowCount) {
            break;
        }
    }
于 2013-10-16T08:05:56.143 回答