{"id":13648658,"url":"https://github.com/tikv/client-rust","last_synced_at":"2025-05-14T08:06:17.502Z","repository":{"id":33126674,"uuid":"146678664","full_name":"tikv/client-rust","owner":"tikv","description":"Rust Client for TiKV.","archived":false,"fork":false,"pushed_at":"2025-04-11T00:32:58.000Z","size":1873,"stargazers_count":395,"open_issues_count":75,"forks_count":134,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-14T03:57:41.046Z","etag":null,"topics":["client","cncf","key-value-store","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tikv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-08-30T01:23:10.000Z","updated_at":"2025-04-06T13:26:58.000Z","dependencies_parsed_at":"2023-11-21T02:27:24.913Z","dependency_job_id":"a9d043b3-1cdb-47bd-98c0-8041dfbc8b2d","html_url":"https://github.com/tikv/client-rust","commit_stats":{"total_commits":603,"total_committers":39,"mean_commits":"15.461538461538462","dds":0.7313432835820896,"last_synced_commit":"8f54e6114227718e256027df2577bbacdf425f86"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Fclient-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Fclient-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Fclient-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tikv%2Fclient-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tikv","download_url":"https://codeload.github.com/tikv/client-rust/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101615,"owners_count":22014909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","cncf","key-value-store","rust"],"created_at":"2024-08-02T01:04:26.031Z","updated_at":"2025-05-14T08:06:12.485Z","avatar_url":"https://github.com/tikv.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# TiKV Client (Rust)\n\n[![Docs](https://img.shields.io/docsrs/tikv-client/latest)](https://docs.rs/tikv-client)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/tikv/client-rust/ci.yml)](https://github.com/tikv/client-rust/actions/workflows/ci.yml)\n\nThis crate provides an easy-to-use client for [TiKV](https://github.com/tikv/tikv), a distributed, transactional key-value database written in Rust.\n\nThis crate lets you connect to a TiKV(\u003e= `v5.0.0`) cluster and use either a transactional or raw (simple get/put style without transactional consistency guarantees) API to access and update your data.\n\nThe TiKV Rust client is an open source (Apache 2) project maintained by the TiKV Authors. We welcome contributions, see below for more info.\n\nNote that the current release is not suitable for production use - APIs are not yet stable and the crate has not been thoroughly tested in real-life use.\n\n## Getting started\n\nThe TiKV client is a Rust library (crate). To use this crate in your project, add the following dependency to your `Cargo.toml`:\n\n```toml\n[dependencies]\ntikv-client = \"0.3\"\n```\n\n### Prerequisites\n\n- [`rust`](https://www.rust-lang.org/) \u003e= `1.56.1`, required for `hashbrown-v0.12.1`\n\nThe general flow of using the client crate is to create either a raw or transaction client object (which can be configured) then send commands using the client object, or use it to create transactions objects. In the latter case, the transaction is built up using various commands and then committed (or rolled back).\n\n### Examples\n\nRaw mode:\n\n```rust\nuse tikv_client::RawClient;\n\nlet client = RawClient::new(vec![\"127.0.0.1:2379\"], None).await?;\nclient.put(\"key\".to_owned(), \"value\".to_owned()).await?;\nlet value = client.get(\"key\".to_owned()).await?;\n```\n\nTransactional mode:\n\n```rust\nuse tikv_client::TransactionClient;\n\nlet txn_client = TransactionClient::new(vec![\"127.0.0.1:2379\"], None).await?;\nlet mut txn = txn_client.begin_optimistic().await?;\ntxn.put(\"key\".to_owned(), \"value\".to_owned()).await?;\nlet value = txn.get(\"key\".to_owned()).await?;\ntxn.commit().await?;\n```\n\nSince the TiKV client provides an async API, you'll need to use an async runtime (we currently only support Tokio). See [getting-started.md](getting-started.md) for a complete example.\n\n## API summary\n\nThe TiKV Rust client supports several levels of abstraction. The most convenient way to use the client is via `RawClient` and `TransactionClient`. This gives a very high-level API which mostly abstracts over the distributed nature of the store and has sensible defaults for all protocols. This interface can be configured, primarily when creating the client or transaction objects via the `Config` and `TransactionOptions` structs. Using some options, you can take over parts of the protocols (such as retrying failed messages) yourself.\n\nThe lowest level of abstraction is to create and send gRPC messages directly to TiKV (and PD) nodes. The `tikv-client-store` and `tikv-client-pd` crates make this easier than using the protobuf definitions and a gRPC library directly, but give you the same level of control.\n\nIn between these levels of abstraction, you can send and receive individual messages to the TiKV cluster, but take advantage of library code for common operations such as resolving data to regions and thus nodes in the cluster, or retrying failed messages. This can be useful for testing a TiKV cluster or for some advanced use cases. See the `client_rust::request` module for this API, and `client_rust::raw::lowering` and `client_rust::transaction::lowering` for convenience methods for creating request objects.\n\nThe rest of this document describes only the `RawClient`/`TransactionClient` APIs.\n\nImportant note: It is **not recommended or supported** to use both the raw and transactional APIs on the same database.\n\n### Types\n\n`Key`: a key in the store. `String` and `Vec\u003cu8\u003e` implement `Into\u003cKey\u003e`, so you can pass them directly into client functions.\n\n`Value`: a value in the store; just an alias of `Vec\u003cu8\u003e`.\n\n`KvPair`: a pair of a `Key` and a `Value`. It provides convenience methods for conversion to and from other types.\n\n`BoundRange`: used for range related requests like `scan`. It implements `From` for Rust ranges so you can pass a Rust range of keys to the request, e.g., `client.delete_range(vec![]..)`.\n\n### Raw requests\n\n| Request            | Main parameter type | Result type             | Noteworthy Behavior                                                            |\n|--------------------|---------------------|-------------------------|--------------------------------------------------------------------------------|\n| `put`              | `KvPair`            |                         |                                                                                |\n| `get`              | `Key`               | `Option\u003cValue\u003e`         |                                                                                |\n| `delete`           | `Key`               |                         |                                                                                |\n| `delete_range`     | `BoundRange`        |                         |                                                                                |\n| `scan`             | `BoundRange`        | `Vec\u003cKvPair\u003e`           |                                                                                |\n| `batch_put`        | `Iter\u003cKvPair\u003e`      |                         |                                                                                |\n| `batch_get`        | `Iter\u003cKey\u003e`         | `Vec\u003cKvPair\u003e`           | Skips non-existent keys; does not retain order                                 |\n| `batch_delete`     | `Iter\u003cKey\u003e`         |                         |                                                                                |\n| `batch_scan`       | `Iter\u003cBoundRange\u003e`  | `Vec\u003cKvPair\u003e`           | See docs for `each_limit` parameter behavior. The order of ranges is retained. |\n| `batch_scan_keys`  | `Iter\u003cBoundRange\u003e`  | `Vec\u003cKey\u003e`              | See docs for `each_limit` parameter behavior. The order of ranges is retained. |\n| `compare_and_swap` | `Key` + 2x `Value`  | `(Option\u003cValue\u003e, bool)` |                                                                                |\n\n### Transactional requests\n\n| Request                | Main parameter type | Result type     | Noteworthy Behavior                                             |\n|------------------------|---------------------|-----------------|-----------------------------------------------------------------|\n| `put`                  | `KvPair`            |                 |                                                                 |\n| `get`                  | `Key`               | `Option\u003cvalue\u003e` |                                                                 |\n| `get_for_update`       | `Key`               | `Option\u003cvalue\u003e` |                                                                 |\n| `key_exists`           | `Key`               | `bool`          |                                                                 |\n| `delete`               | `Key`               |                 |                                                                 |\n| `scan`                 | `BoundRange`        | `Iter\u003cKvPair\u003e`  |                                                                 |\n| `scan_keys`            | `BoundRange`        | `Iter\u003cKey\u003e`     |                                                                 |\n| `batch_get`            | `Iter\u003cKey\u003e`         | `Iter\u003cKvPair\u003e`  | Skips non-existent keys; does not retain order                  |\n| `batch_get_for_update` | `Iter\u003cKey\u003e`         | `Iter\u003cKvPair\u003e`  | Skips non-existent keys; does not retain order                  |\n| `lock_keys`            | `Iter\u003cKey\u003e`         |                 |                                                                 |\n| `send_heart_beat`      |                     | `u64` (TTL)     |                                                                 |\n| `gc`                   | `Timestamp`         | `bool`          | Returns true if the latest safepoint in PD equals the parameter |\n\n# Development and contributing\n\nWe welcome your contributions! Contributing code is great, we also appreciate filing [issues](https://github.com/tikv/client-rust/issues/new) to identify bugs and provide feedback, adding tests or examples, and improvements to documentation.\n\n## Building and testing\n\nWe use the standard Cargo workflows, e.g., `cargo build` to build and `cargo test/nextest` to run unit tests. You will need to use a nightly Rust toolchain to build and run tests. Could use [nextest](https://nexte.st/index.html) to speed up ut, install nextest first.\n\n```\ncargo install cargo-nextest --locked\n```\n\nRunning integration tests or manually testing the client with a TiKV cluster is a little bit more involved. The easiest way is to use [TiUp](https://github.com/pingcap/tiup) (\u003e= 1.5) to initialise a cluster on your local machine:\n\n```\ntiup playground nightly --mode tikv-slim\n```\n\nThen if you want to run integration tests:\n\n```\nPD_ADDRS=\"127.0.0.1:2379\" cargo test --package tikv-client --test integration_tests --features integration-tests\n```\n\n## Creating a PR\n\nWe use a standard GitHub PR workflow. We run CI on every PR and require all PRs to build without warnings (including clippy and Rustfmt warnings), pass tests, have a DCO sign-off (use `-s` when you commit, the DCO bot will guide you through completing the DCO agreement for your first PR), and have at least one review. If any of this is difficult for you, don't worry about it and ask on the PR.\n\nTo run CI-like tests locally, we recommend you run `cargo clippy`, `cargo test/nextest run`, and `cargo fmt` before submitting your PR. See above for running integration tests, but you probably won't need to worry about this for your first few PRs.\n\nPlease follow PingCAP's  [Rust style guide](https://pingcap.github.io/style-guide/rust/). All code PRs should include new tests or test cases.\n\n## Getting help\n\nIf you need help, either to find something to work on, or with any technical problem, the easiest way to get it is via internals.tidb.io, the forum for TiDB developers.\n\nYou can also ask in Slack. We monitor the #client-rust channel on the [tikv-wg slack](https://tikv.org/chat).\n\nYou can just ask a question on GitHub issues or PRs directly; if you don't get a response, you should ping @ekexium or @andylokandy.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftikv%2Fclient-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftikv%2Fclient-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftikv%2Fclient-rust/lists"}