mirror of https://github.com/tikv/website.git
Refine structure/flow
Signed-off-by: Ana Hobden <operator@hoverbear.org>
This commit is contained in:
parent
f400631b6b
commit
a3f1b6895d
|
|
@ -24,20 +24,7 @@ There are several clients that connect to TiKV:
|
|||
|
||||
Below we use the Rust client for some examples, but you should find all clients work similarly.
|
||||
|
||||
## Basic Types
|
||||
|
||||
Both client use a few basic types for most of their API:
|
||||
|
||||
* `Key`, a wrapper around a `Vec<u8>` symbolizing the 'key' in a key-value pair.
|
||||
* `Value`, a wrapper around a `Vec<u8>` symbolizing the 'value' in a key-value pair.
|
||||
* `KvPair`, a tuple of `(Key, Value)` representing a key-value pair.
|
||||
* `KeyRange`, a trait representing a range of `Key`s from one value to either another value, or the end of the entire dataset.
|
||||
|
||||
The `Key` and `Value` types implement `Deref<Target=Vec<u8>>` so they can generally be used just like their contained values. Where possible API calls accept `impl Into<T>` instead of the type `T` when it comes to `Key`, `Value`, and `KvPair`.
|
||||
|
||||
If you're using your own key or value types, we reccomend implementing `Into<Key>` and/or `Into<Value>` for them where appropriate. You can also `impl KeyRange` if you have any range types.\
|
||||
|
||||
## Connect a client
|
||||
## Adding the dependency {#dependency}
|
||||
|
||||
This guide assumes you are using Rust 1.31 or above. You will also need an already deployed TiKV and PD cluster, since TiKV is not an embedded database.
|
||||
|
||||
|
|
@ -51,6 +38,21 @@ tikv-client = { git = "https://github.com/tikv/client-rust" }
|
|||
futures = "0.1"
|
||||
```
|
||||
|
||||
## Basic Types {#types}
|
||||
|
||||
Both client use a few basic types for most of their API:
|
||||
|
||||
* `Key`, a wrapper around a `Vec<u8>` symbolizing the 'key' in a key-value pair.
|
||||
* `Value`, a wrapper around a `Vec<u8>` symbolizing the 'value' in a key-value pair.
|
||||
* `KvPair`, a tuple of `(Key, Value)` representing a key-value pair.
|
||||
* `KeyRange`, a trait representing a range of `Key`s from one value to either another value, or the end of the entire dataset.
|
||||
|
||||
The `Key` and `Value` types implement `Deref<Target=Vec<u8>>` so they can generally be used just like their contained values. Where possible API calls accept `impl Into<T>` instead of the type `T` when it comes to `Key`, `Value`, and `KvPair`.
|
||||
|
||||
If you're using your own key or value types, we reccomend implementing `Into<Key>` and/or `Into<Value>` for them where appropriate. You can also `impl KeyRange` if you have any range types.
|
||||
|
||||
## Connect a client {#connnect}
|
||||
|
||||
In your `src/main.rs` you can then import the raw API as well as the functionality of the `Future` trait so you can utilize it.
|
||||
|
||||
*Note:* In this example we used `raw`, but you can also use `transaction`. The process is the same.
|
||||
|
|
@ -74,26 +76,17 @@ let config = Config::new(vec.
|
||||
> The transactional API of the Rust client is incomplete. You can track the progress with [issue #15](https://github.com/tikv/client-rust/issues/15). For a complete implementation, you can try the [Go client](https://github.com/pingcap/tidb/store/tikv).
|
||||
|
||||
Using a connected `transaction::Client` you can then begin a transaction:
|
||||
|
||||
|
|
@ -177,20 +170,28 @@ req.wait()?;
|
|||
|
||||
let req = txn.get(key).wait()?;
|
||||
assert_eq!(result, None);
|
||||
|
||||
// For more detail on scanning, see the raw section above or the documentation.
|
||||
let req = client.scan("A".."B", 1000);
|
||||
let result: Vec<KvPair> = req.wait()?;
|
||||
```
|
||||
|
||||
When you're ready to commit these changes, you can commit the change:
|
||||
When you're ready to commit these changes, you can commit the change, if you'd preferable to abort the operation you can rollback:
|
||||
|
||||
```rust
|
||||
txn.commit()?;
|
||||
```
|
||||
|
||||
If it's preferable to abort the operation it's possible to rollback the transaction:
|
||||
|
||||
```rust
|
||||
txn.rollback()?
|
||||
if all_is_good {
|
||||
txn.commit()?;
|
||||
} else {
|
||||
txn.rollback()?
|
||||
}
|
||||
```
|
||||
|
||||
## Beyond the Basics
|
||||
|
||||
At this point you're familiar with the basic functionality of TiKV. To begin integrating with TiKV you should explore the documentation of your favorite client from those we listed above.
|
||||
|
||||
For the Rust client, you can find the full documentation for the client (and all your dependencies) by running:
|
||||
|
||||
```bash
|
||||
cargo doc --package tikv-client --open
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in New Issue