Can someone help me on how to set consistency level separately for read and write in cassandra (cqlsh) and one more question can we set consistency level for a keyspace? please explain
3 Answers
Yes, you can set consistency level other then your default consistency level. (which you have defined while building your cluster object).
Here is the example of setting consistency level to your prepared statement.
session.prepare(<Query>).setConsistencyLevel(<consistency_level>)
If you are using JAVA driver, you can explore the enum class ConsistencyLevel defined in the datastax driver library.
import com.datastax.driver.core.ConsistencyLevel.{consistency_level}
This link might help you dmlConfigConsistency
For setting this in cqlsh you need to issue corresponding CONSISTENCY command before executing the specific query, like this:
CONSISTENCY QUORUM;
INSERT INTO ... ;
Setting the consistency level for "class" of queries is impossible in cqlsh...
You can set consistency after login CQLSH like below for read and write. CONSISTENCY ONE/TWO; etc https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlshConsistency.html
Also,you can refer below for setting a Consistency Level with Prepared Statements https://datastax.github.io/python-driver/getting_started.html