Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create README.md #34

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Go client for TiKV
------------

RawAPI (provide atomic read/write on single key-value level), example:

```
package main

import (
"context"
"fmt"

"github.com/tikv/client-go/config"
"github.com/tikv/client-go/rawkv"
)

func main() {
cli, err := rawkv.NewClient(context.TODO(), []string{"127.0.0.1:2379"}, config.Default())
if err != nil {
panic(err)
}
defer cli.Close()

fmt.Printf("cluster ID: %d\n", cli.ClusterID())

key := []byte("Company")
val := []byte("PingCAP")

// put key into tikv
err = cli.Put(context.TODO(), key, val)
if err != nil {
panic(err)
}
fmt.Printf("Successfully put %s:%s to tikv\n", key, val)

// get key from tikv
val, err = cli.Get(context.TODO(), key)
if err != nil {
panic(err)
}
fmt.Printf("found val: %s for key: %s\n", val, key)

// delete key from tikv
err = cli.Delete(context.TODO(), key)
if err != nil {
panic(err)
}
fmt.Printf("key: %s deleted\n", key)

// get key again from tikv
val, err = cli.Get(context.TODO(), key)
if err != nil {
panic(err)
}
fmt.Printf("found val: %s for key: %s\n", val, key)
}
```

Transactional API (provide cross-row transaction support with SI(Snapshot Isolation) level), example:

```
package main

import (
"context"
"flag"
"fmt"

"github.com/tikv/client-go/config"
"github.com/tikv/client-go/txnkv"
)

var (
pdAddr = flag.String("pd", "127.0.0.1:2379", "pd address")
)

func main() {
client, err := txnkv.NewClient(context.TODO(), []string{*pdAddr}, config.Default())
if err != nil {
panic(err)
}
defer client.Close()

tx, err := client.Begin(context.TODO())
if err != nil {
panic(err)
}

tx.Set([]byte("k1"), []byte("v1"))
tx.Set([]byte("k2"), []byte("v2"))

tx.Commit(context.Background())

tx, err = client.Begin(context.TODO())
var v1, v2 []byte
v1, err = tx.Get(context.TODO(), []byte("k1"))
v2, err = tx.Get(context.TODO(), []byte("k2"))
fmt.Println(v1, v2)
}
```