battlecook
battlecook

Reputation: 551

How do I apply read and write consistency in gocql?

I am using https://github.com/gocql/gocql. I want to set the read/write consistency of cassandra.

cluster := gocql.NewCluster(hosts...)
cluster.Consistency = gocql.ParseConsistency(consistency)

If the consistency setting is applied as above, is both read/write consistency applied? Or is there a way to apply read and write consistency separately?

Upvotes: 1

Views: 530

Answers (1)

Erick Ramirez
Erick Ramirez

Reputation: 16353

You can set the global consistency with:

    cluster.Consistency = gocql.LocalQuorum

This will apply to both reads and writes. There is no way to configure a different CL for either just reads or just writes with the GoCQL driver.

As an alternative, you can set the consistency for the session or just the query with either Consistency() or SetConsistency(). For example:

    session.Query(query, ...).Consistency(gocql.One)

The valid consistency constants are:

    Any
    One
    Two
    Three
    Quorum
    All
    LocalQuorum
    EachQuorum
    LocalOne

Note that the general recommendation is to use local quorum for almost all cases. Cheers!

Upvotes: 1

Related Questions