Java Client

Interact with TiKV using Java.

This document guides you on how to use Java Client in TiKV.

TiKV Java Client is developed and released using Java8. The minimum supported version of TiKV is 2.0.0.

Add the dependency

To start, open the pom.xml of your project, and add the tikv-client-java as dependencies if you are using Maven.


Try the Raw key-value API

Using a connected org.tikv.raw.RawKVClient, you can perform actions such as put, get, delete, and scan:

import java.util.List;
import org.tikv.common.TiConfiguration;
import org.tikv.common.TiSession;
import org.tikv.kvproto.Kvrpcpb;
import org.tikv.raw.RawKVClient;

TiConfiguration conf = TiConfiguration.createRawDefault("");
TiSession session = TiSession.create(conf);
RawKVClient client = session.createRawClient();

ByteString key = ByteString.copyFromUtf8("Hello");
ByteString value = ByteString.copyFromUtf8("RawKV");

// put
client.put(key, value);

// get
ByteString result = client.get(key);

// delete

// get
result = client.get(key);

// scan
int limit = 1000;
client.put(ByteString.copyFromUtf8("k1"), ByteString.copyFromUtf8("v1"));
client.put(ByteString.copyFromUtf8("k2"), ByteString.copyFromUtf8("v2"));
client.put(ByteString.copyFromUtf8("k3"), ByteString.copyFromUtf8("v3"));
client.put(ByteString.copyFromUtf8("k4"), ByteString.copyFromUtf8("v4"));

List<Kvrpcpb.KvPair> list = client.scan(ByteString.copyFromUtf8("k1"), ByteString.copyFromUtf8("k5"), limit);
for(Kvrpcpb.KvPair pair : list) {

These functions also have batch variants (batchPut, batchGet, batchDelete, and batchScan) which considerably reduce network overhead and increase performance under certain workloads.

You can find all functions supported by RawKVClient in this JAVA file.

Transactional key-value API

Transactional key-value API is still in the stage of prove-of-concept and under heavy development.