CQL for Cassandra 2.x

Using lightweight transactions

INSERT and UPDATE statements that use the IF clause support lightweight transactions, also known as Compare and Set (CAS).

INSERT and UPDATE statements using the IF clause, support lightweight transactions, also known as Compare and Set (CAS).

Procedure

  1. Register a new user.
    INSERT INTO users (login, email, name, login_count)
      VALUES ('jdoe', 'jdoe@abc.com', 'Jane Doe', 1)
      IF NOT EXISTS;
  2. Perform a CAS operation against a row that does exist by adding the predicate for the operation at the end of the query. For example, reset Jane Doe's password.
    UPDATE users
      SET email = ‘janedoe@abc.com’
      WHERE login = 'jdoe'
      IF email = ‘jdoe@abc.com’;

Attention: Be sure this document version matches your product version

Show/hide