mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-20 03:29:45 +02:00
add hbase doc
This commit is contained in:
parent
3f2c51b56e
commit
f5d91d6d8c
@ -0,0 +1,50 @@
|
||||
# database/hbase
|
||||
|
||||
## 说明
|
||||
Hbase Client,进行封装加入了链路追踪和统计。
|
||||
|
||||
## 配置
|
||||
需要指定hbase集群的zookeeper地址。
|
||||
```
|
||||
config := &hbase.Config{Zookeeper: &hbase.ZKConfig{Addrs: []string{"localhost"}}}
|
||||
client := hbase.NewClient(config)
|
||||
```
|
||||
|
||||
## 使用方式
|
||||
```
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/bilibili/kratos/pkg/database/hbase"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config := &hbase.Config{Zookeeper: &hbase.ZKConfig{Addrs: []string{"localhost"}}}
|
||||
client := hbase.NewClient(config)
|
||||
|
||||
//
|
||||
values := map[string]map[string][]byte{"name": {"firstname": []byte("hello"), "lastname": []byte("world")}}
|
||||
ctx := context.Background()
|
||||
|
||||
// 写入信息
|
||||
// table: user
|
||||
// rowkey: user1
|
||||
// values["family"] = columns
|
||||
_, err := client.PutStr(ctx, "user", "user1", values)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 读取信息
|
||||
// table: user
|
||||
// rowkey: user1
|
||||
result, err := client.GetStr(ctx, "user", "user1")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("%v", result)
|
||||
}
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user