mirror of https://github.com/tikv/website.git
1.7 KiB
1.7 KiB
| title | description | weight | draft |
|---|---|---|---|
| APIs | Interact with TiKV using the raw key-value API or the transactional key-value API | 4 | true |
TiKV offers two APIs that you can use to interact with it:
- A raw API
- A transactional API
Raw key-value API
The raw key-value API is a simple API that enables you to interact with TiKV
To try out the raw key-value API:
-
Install the necessary packages:
go get -v -u github.com/pingcap/tidb/store/tikv -
Import the dependency packages:
import ( "fmt" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/store/tikv" ) -
Create a raw key-value client:
cli, err := tikv.NewRawKVClient([]string{"192.168.199.113:2379"}, config.Security{})Description of two parameters in the above command:
string: a list of PD servers' addressesconfig.Security: used to establish TLS connections, usually left empty when you do not need TLS
-
Call the Raw Key-Value client methods to access the data on TiKV. The Raw Key-Value API contains the following methods, and you can also find them in the GoDoc.
type RawKVClient struct func (c *RawKVClient) Close() error func (c *RawKVClient) ClusterID() uint64 func (c *RawKVClient) Delete(key []byte) error func (c *RawKVClient) Get(key []byte) ([]byte, error) func (c *RawKVClient) Put(key, value []byte) error func (c *RawKVClient) Scan(startKey []byte, limit int) (keys [][]byte, values [][]byte, err error)