2 Star 0 Fork 0

djienet / kratos

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
database-hbase.md 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
chenli 提交于 2020-11-02 15:38 . update

database/hbase

说明

Hbase Client,进行封装加入了链路追踪和统计。

配置

需要指定hbase集群的zookeeper地址。

config := &hbase.Config{Zookeeper: &hbase.ZKConfig{Addrs: []string{"localhost"}}}
client := hbase.NewClient(config)

使用方式

package main

import (
	"context"
	"fmt"
    
    "gitee.com/djienet/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)
}

文档目录树

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/djienet/kratos.git
git@gitee.com:djienet/kratos.git
djienet
kratos
kratos
v1.1.7

搜索帮助

344bd9b3 5694891 D2dac590 5694891