mirror of https://github.com/tikv/client-java.git
Signed-off-by: pingyu <yuping@pingcap.com> Signed-off-by: pingyu <yuping@pingcap.com>
This commit is contained in:
parent
8cb7a8294c
commit
870a9fb8bc
34
README.md
34
README.md
|
@ -4,18 +4,17 @@
|
|||
|
||||
## TiKV JAVA Client
|
||||
|
||||
A Java client for [TiDB](https://github.com/pingcap/tidb)/[TiKV](https://github.com/tikv/tikv).
|
||||
A Java client for [TiKV](https://github.com/tikv/tikv).
|
||||
It is supposed to:
|
||||
+ Communicate via [gRPC](http://www.grpc.io/)
|
||||
+ Talk to Placement Driver searching for a region
|
||||
+ Talk to TiKV for reading/writing data and the resulted data is encoded/decoded just like what we do in TiDB.
|
||||
+ Talk to Coprocessor for calculation pushdown
|
||||
+ Talk to TiKV for reading/writing data
|
||||
|
||||
## Quick Start
|
||||
|
||||
> TiKV Java Client is designed to communicate with [pd](https://github.com/tikv/pd) and [tikv](https://github.com/tikv/tikv), please run TiKV and PD in advance.
|
||||
> TiKV Java Client is designed to communicate with [PD](https://github.com/tikv/pd) and [TiKV](https://github.com/tikv/tikv), please run PD and TiKV in advance.
|
||||
|
||||
Build java client from source file:
|
||||
Build Java client from source file:
|
||||
|
||||
```sh
|
||||
mvn clean install -Dmaven.test.skip=true
|
||||
|
@ -27,11 +26,27 @@ Add maven dependency to `pom.xml`:
|
|||
<dependency>
|
||||
<groupId>org.tikv</groupId>
|
||||
<artifactId>tikv-client-java</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
Create a RawKVClient and communicates with TiKV:
|
||||
Create a transactional `KVClient` and communicates with TiKV:
|
||||
|
||||
```java
|
||||
import org.tikv.common.TiConfiguration;
|
||||
import org.tikv.common.TiSession;
|
||||
import org.tikv.txn.KVClient;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TiConfiguration conf = TiConfiguration.createDefault(YOUR_PD_ADDRESSES);
|
||||
TiSession session = TiSession.create(conf);
|
||||
KVClient client = session.createKVClient();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Or create a `RawKVClient` if you don't need the transaction semantic:
|
||||
|
||||
```java
|
||||
import org.tikv.common.TiConfiguration;
|
||||
|
@ -39,8 +54,7 @@ import org.tikv.common.TiSession;
|
|||
import org.tikv.raw.RawKVClient;
|
||||
|
||||
public class Main {
|
||||
public static void main() {
|
||||
// You MUST create a raw configuration if you are using RawKVClient.
|
||||
public static void main(String[] args) throws Exception {
|
||||
TiConfiguration conf = TiConfiguration.createRawDefault(YOUR_PD_ADDRESSES);
|
||||
TiSession session = TiSession.create(conf);
|
||||
RawKVClient client = session.createRawClient();
|
||||
|
@ -48,7 +62,7 @@ public class Main {
|
|||
}
|
||||
```
|
||||
|
||||
Find more demo in [KVRawClientTest](https://github.com/birdstorm/KVRawClientTest/)
|
||||
Find more demo in [TiKV Java Client User Documents](https://tikv.github.io/client-java/examples/introduction.html)
|
||||
|
||||
## Documentation
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ Add maven dependency to `pom.xml`.
|
|||
<dependency>
|
||||
<groupId>org.tikv</groupId>
|
||||
<artifactId>tikv-client-java</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.tikv.raw.RawKVClient;
|
|||
import org.tikv.shade.com.google.protobuf.ByteString;
|
||||
|
||||
public class Main {
|
||||
public static void main() {
|
||||
public static void main(String[] args) throws Exception {
|
||||
// You MUST create a raw configuration if you are using RawKVClient.
|
||||
TiConfiguration conf = TiConfiguration.createRawDefault("127.0.0.1:2379");
|
||||
TiSession session = TiSession.create(conf);
|
||||
|
@ -61,7 +61,7 @@ To enable the API V2 mode, users need to specify the API version of the client.
|
|||
import org.tikv.common.TiConfiguration.ApiVersion;
|
||||
|
||||
public class Main {
|
||||
public static void main() {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TiConfiguration conf = TiConfiguration.createRawDefault("127.0.0.1:2379");
|
||||
conf.setApiVersion(ApiVersion.V2);
|
||||
try(TiSession session = TiSession.create(conf)) {
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.tikv.txn.TwoPhaseCommitter;
|
|||
|
||||
public class App {
|
||||
public static void main(String[] args) throws Exception {
|
||||
TiConfiguration conf = TiConfiguration.createDefault("127.0.0.1:2389");
|
||||
TiConfiguration conf = TiConfiguration.createDefault("127.0.0.1:2379");
|
||||
try (TiSession session = TiSession.create(conf)) {
|
||||
// two-phrase write
|
||||
long startTS = session.getTimestamp().getVersion();
|
||||
|
|
Loading…
Reference in New Issue