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

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

  1. import com.google.protobuf.ByteString;
  2. import java.util.List;
  3. import org.tikv.common.TiConfiguration;
  4. import org.tikv.common.TiSession;
  5. import org.tikv.kvproto.Kvrpcpb;
  6. import org.tikv.raw.RawKVClient;
  7. TiConfiguration conf = TiConfiguration.createRawDefault("127.0.0.1:2379");
  8. TiSession session = TiSession.create(conf);
  9. RawKVClient client = session.createRawClient();
  10. ByteString value = ByteString.copyFromUtf8("RawKV");
  11. // put
  12. client.put(key, value);
  13. // get
  14. ByteString result = client.get(key);
  15. assert("RawKV".equals(result.toStringUtf8()));
  16. System.out.println(result.toStringUtf8());
  17. // delete
  18. client.delete(key);
  19. result = client.get(key);
  20. System.out.println(result.toStringUtf8());
  21. // scan
  22. int limit = 1000;
  23. client.put(ByteString.copyFromUtf8("k1"), ByteString.copyFromUtf8("v1"));
  24. client.put(ByteString.copyFromUtf8("k2"), ByteString.copyFromUtf8("v2"));
  25. client.put(ByteString.copyFromUtf8("k3"), ByteString.copyFromUtf8("v3"));
  26. client.put(ByteString.copyFromUtf8("k4"), ByteString.copyFromUtf8("v4"));
  27. List<Kvrpcpb.KvPair> list = client.scan(ByteString.copyFromUtf8("k1"), ByteString.copyFromUtf8("k5"), limit);
  28. for(Kvrpcpb.KvPair pair : list) {
  29. }

You can find all functions supported by RawKVClient .