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
:
import com.google.protobuf.ByteString;
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("127.0.0.1:2379");
TiSession session = TiSession.create(conf);
RawKVClient client = session.createRawClient();
ByteString value = ByteString.copyFromUtf8("RawKV");
// put
client.put(key, value);
// get
ByteString result = client.get(key);
assert("RawKV".equals(result.toStringUtf8()));
System.out.println(result.toStringUtf8());
// delete
client.delete(key);
result = client.get(key);
System.out.println(result.toStringUtf8());
// 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) {
}
You can find all functions supported by RawKVClient
.