score:1

If you are using Cassandra 2.0 then you can do this using the normal INSERT CQL statement followed by IF NOT EXISTS:

INSERT INTO your_table (key1) values ("1_100") IF NOT EXISTS

As shown here, this is best done with CQL and the native CQL driver; the functionality is exposed over Thrift as the cas method, but neither the cli nor Hector have been updated to support this and probably never will be.

If you are using Cassandra 1.2 or older, this is not possible.

score:1

val rangeSlice = HFactory.createRangeSlicesQuery(keyspace, se, se, se)
rangeSlice.setColumnFamily("myTable")
rangeSlice.setKeys(null, null)
rangeSlice.setRange(null, null, true, Int.MaxValue)
val bIterator = rangeSlice.execute().get.iterator()
while (bIterator.hasNext()) {
  val myRow = bIterator.next()
  val myKey = myRow.getKey()
  println(myKey+"<<<this is key")
  }

score:1

val rangeSlice = HFactory.createRangeSlicesQuery(keyspace, se, se, se)
rangeSlice.setColumnFamily("myTable")
rangeSlice.setReturnKeysOnly();
val bIterator = rangeSlice.execute().get.iterator()
while (bIterator.hasNext()) {
val myKey =bIterator.next().getKey()
 println(myKey+"<<<this is key")
}

Related Query

More Query from same tag