mirror of https://github.com/tikv/website.git
Batch update TiKV docs
Signed-off-by: TomShawn <41534398+TomShawn@users.noreply.github.com>
This commit is contained in:
parent
731f10e240
commit
ed7af509db
|
|
@ -1,13 +1,13 @@
|
|||
---
|
||||
title: Operate TiKV
|
||||
description: Learn how to maintain and operate a TiKV cluster
|
||||
description: Learn how to maintain and operate a TiKV cluster.
|
||||
menu:
|
||||
"5.1":
|
||||
parent: Deploy
|
||||
weight: 5
|
||||
---
|
||||
|
||||
This section introduces how to maintain and operate a TiKV cluster.
|
||||
This section introduces how to maintain and operate a TiKV cluster, including the following operations:
|
||||
|
||||
- [Upgrade a TiKV cluster using TiUP](../upgrade)
|
||||
- [Scale out/in a TiKV cluster using TiUP](../scale)
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ menu:
|
|||
weight: 5
|
||||
---
|
||||
|
||||
TiKV client for C++ is built on top of [TiKV Client in Rust](https://github.com/tikv/client-rust) via [cxx](https://github.com/dtolnay/cxx).
|
||||
|
||||
This client is still in the stage of prove-of-concept and under heavy development. You can track development at [tikv/client-cpp](https://github.com/tikv/client-cpp/) repository.
|
||||
|
||||
{{< warning >}}
|
||||
You are not suggested to use the C++ client for production use until it is released.
|
||||
Currently, the TiKV client for C++ is not released yet.
|
||||
{{< /warning >}}
|
||||
|
||||
The TiKV client in C++ is built on top of [TiKV client in Rust](https://github.com/tikv/client-rust) using [cxx](https://github.com/dtolnay/cxx).
|
||||
|
||||
This C++ client is still in the stage of prove-of-concept and under heavy development. You can track the development progress at the [tikv/client-cpp](https://github.com/tikv/client-cpp/) repository.
|
||||
|
|
|
|||
|
|
@ -1,26 +1,39 @@
|
|||
---
|
||||
title: TTL
|
||||
description: How to use RawKV's TTL API
|
||||
description: How to use TTL via RawKV API.
|
||||
menu:
|
||||
"5.1":
|
||||
parent: RawKV
|
||||
weight: 4
|
||||
---
|
||||
|
||||
This document walks you through how to use RawKV’s `TTL` API.
|
||||
Time To Live (TTL) is ... TiKV provides the TTL support via the RawKV API. <!-- Please provide a short introduction of TTL or RawKV's TTL API. What is it? In what situations users might need to use it? -->
|
||||
|
||||
## Config TiKV to enable TTL
|
||||
This document provides two examples to show you how to set TTL via the RawKV API.
|
||||
|
||||
TTL is disabled by default. Use the following TiKV configuration to enable TTL.
|
||||
## Enable TTL
|
||||
|
||||
Before you set TTL via RawKV API, you must enable TTL in your TiKV cluster.
|
||||
|
||||
TTL is disabled by default. To enable it, set the following TiKV configuration to `true`.
|
||||
|
||||
```yaml
|
||||
[storage]
|
||||
enable-ttl = true
|
||||
```
|
||||
|
||||
## Java
|
||||
## Use TTL in Java client
|
||||
|
||||
The following example shows a simple example of how to use `TTL` int `put` API.
|
||||
After TTL is enabled in TiKV, you can set it in Java client via the `put` API or `CAS` API. The following two examples shows how to set TTL via the `put` API and `CAS` API.
|
||||
|
||||
### Set TTL in the `put` API
|
||||
|
||||
In the following examples, these operations are performed:
|
||||
|
||||
1. Two key-value pairs, `(k1, v1)` and `(k2, v2)`, are written into TiKV via the `put` API. `(k1, v1)` is written with a TTL of 10 seconds. `(k2, v2)` is written without TTL.
|
||||
2. Try to read `k1` and `k2` from TiKV. Both values are returned.
|
||||
3. Let TiKV sleep for 10 seconds, which is the time of TTL.
|
||||
4. Try to read `k1` and `k2` from TiKV. `v2` is returned, but `v1` is not returned because the TTL has expired.
|
||||
|
||||
```java
|
||||
import java.util.Optional;
|
||||
|
|
@ -33,44 +46,46 @@ TiConfiguration conf = TiConfiguration.createRawDefault("127.0.0.1:2379");
|
|||
TiSession session = TiSession.create(conf);
|
||||
RawKVClient client = session.createRawClient();
|
||||
|
||||
// write (k1, v1) with ttl=10 seconds
|
||||
// Writes the (k1, v1) into TiKV with a TTL of 10 seconds.
|
||||
client.put(ByteString.copyFromUtf8("k1"), ByteString.copyFromUtf8("v1"), 10);
|
||||
|
||||
// write (k2, v2) without ttl
|
||||
// Writes the (k2, v2) into TiKV without TTL.
|
||||
client.put(ByteString.copyFromUtf8("k2"), ByteString.copyFromUtf8("v2"));
|
||||
|
||||
// get k1 returns v1
|
||||
// Reads k1 from TiKV. v1 is returned.
|
||||
Optional<ByteString> result1 = client.get(ByteString.copyFromUtf8("k1"));
|
||||
assert(result1.isPresent());
|
||||
assert("v1".equals(result1.get().toStringUtf8()));
|
||||
System.out.println(result1.get().toStringUtf8());
|
||||
|
||||
// get k2 returns v2
|
||||
// Reads k2 from TiKV. v2 is returned.
|
||||
Optional<ByteString> result2 = client.get(ByteString.copyFromUtf8("k2"));
|
||||
assert(result2.isPresent());
|
||||
assert("v2".equals(result2.get().toStringUtf8()));
|
||||
System.out.println(result2.get().toStringUtf8());
|
||||
|
||||
// sleep 10 seconds
|
||||
// Let TiKV sleep for 10 seconds.
|
||||
System.out.println("Sleep 10 seconds.");
|
||||
Thread.sleep(10000);
|
||||
|
||||
// get k1 returns null, cause k1's ttl is expired
|
||||
// Reads k1 from TiKV. NULL is returned, because k1's TTL has expired.
|
||||
result1 = client.get(ByteString.copyFromUtf8("k1"));
|
||||
assert(!result1.isPresent());
|
||||
|
||||
// get k2 returns v2
|
||||
// Reads k2 from TiKV. v2 is returned.
|
||||
result2 = client.get(ByteString.copyFromUtf8("k2"));
|
||||
assert(result2.isPresent());
|
||||
assert("v2".equals(result2.get().toStringUtf8()));
|
||||
System.out.println(result2.get().toStringUtf8());
|
||||
|
||||
// close
|
||||
// Close
|
||||
client.close();
|
||||
session.close();
|
||||
```
|
||||
|
||||
`TTL` is also supported in the `CAS` API. Let's see an example.
|
||||
## Set TTL in the `CAS` API
|
||||
|
||||
You can also set TTL via the `CAS` API. See the following example:
|
||||
|
||||
```java
|
||||
import java.util.Optional;
|
||||
|
|
@ -114,4 +129,4 @@ client.close();
|
|||
session.close();
|
||||
```
|
||||
|
||||
The code example used in this chapter can be found [here](https://github.com/marsishandsome/tikv-client-examples/blob/main/java-example/src/main/java/example/rawkv/TTL.java).
|
||||
The example code above is available [here](https://github.com/marsishandsome/tikv-client-examples/blob/main/java-example/src/main/java/example/rawkv/TTL.java).
|
||||
|
|
|
|||
|
|
@ -7,6 +7,6 @@ menu:
|
|||
weight: 3
|
||||
---
|
||||
|
||||
Starting with TiKV 4.0, TiUP, as the package manager, makes it far easier to manage different cluster components in the TiKV ecosystem.
|
||||
Starting with TiKV 4.0, TiUP, as the package manager, makes it easier to manage different cluster components in the TiKV ecosystem.
|
||||
|
||||
Please refer to [TiUP documentation guide](https://docs.pingcap.com/tidb/stable/tiup-documentation-guide) to find more TiUP commands and usages.
|
||||
Refer to the [TiUP documentation guide](https://docs.pingcap.com/tidb/stable/tiup-documentation-guide) to find more TiUP commands and usages.
|
||||
|
|
|
|||
Loading…
Reference in New Issue