Skip to content

Instantly share code, notes, and snippets.

@spidaman
Created May 13, 2010 06:14
Show Gist options
  • Save spidaman/399554 to your computer and use it in GitHub Desktop.
Save spidaman/399554 to your computer and use it in GitHub Desktop.
public boolean has_key(String keySpace, String columnFamilyName, String key) throws Exception {
TTransport tr = new TSocket("localhost", 9160);
TProtocol proto = new TBinaryProtocol(tr);
Cassandra.Client client = new Cassandra.Client(proto);
tr.open();
SlicePredicate predicate = new SlicePredicate();
SliceRange sliceRange = new SliceRange();
sliceRange.setCount(1);
sliceRange.setStart(new byte[0]);
sliceRange.setFinish(new byte[0]);
predicate.setSlice_range(sliceRange);
ColumnParent columnParent = new ColumnParent(columnFamilyName);
List<ColumnOrSuperColumn> result = client.get_slice(keySpace, key, columnParent, predicate, ConsistencyLevel.ALL);
return result.size() > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment