cassandracassandra-2.0astyanax

Difference between KeyRange and KeySlice in astayanx APIs


What is the difference between KeyRange and KeySlice APIs in Astyanax?


Solution

  • Based on the Astyanax documentation, it looks like getKeyRange retrieves data based on a range of two keys. Essentially, this is equivalent of a key-based greater-than/less-than query.

    Additionally, getKeySlice retrieves data based on a specific list of (non-contiguous) keys. This would be equivalent to querying for data having a key present IN the list.

    Their GitHub "Getting Started" page has an example of how to use getKeySlice under "Reading a set of non-contiguous rows."

    OperationResult<Rows<String, String>> result =
      ks.prepareQuery(CF_STANDARD1)
        .getKeySlice("Key1", "Key2", "Key3")
        .execute();
    

    Check the documentation (linked above) for more information.