Skip to content

RawKV Basic

disksing edited this page Dec 9, 2021 · 5 revisions

If you don't need transaction and multi-version support, you can consider using TiKV in the rawkv way, which usually has a faster response time.

Note: Currently a TiKV cluster can only choose one of the rawkv or txnkv APIs to use. Mixing them will cause unavailability issues due to inconsistent key encoding.

The simple usage of rawkv can be found in example usage.

CAS (Compare And Swap) support

By using CAS, we can guarantee that the value is written only when the old value is equal to the provided one.

Note: To use CAS, you must set client.SetAtomicForCAS(true) for all the clients before you use them. If there are some clients in the cluster that are not set up correctly, it may break the CAS constraints.

TTL (Time To Live) support

You can specify the time it survives in seconds when you put the key-value pair. After the time is exceeded, TiKV will automatically clear the corresponding data, or at least ensure that it will return null when queried - as if the data did not exist.

Note that the TTL cleanup depends on the local clock of the tikv-server. It is necessary to ensure the accuracy of the clock by means of NTP etc.

GetKeyTTL can be used to query the TTL of a key. The returned value is the left seconds of the TTL. If the key does not exist, it returns nil. If the key exists but has no TTL, it returns 0.

Clone this wiki locally