键值存储
This commit is contained in:
parent
d0ca855fdc
commit
8671b40884
|
|
@ -12,6 +12,11 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
v := []byte("asdfsdfdsf")
|
||||
consul.KVPut("hello", &v, 0)
|
||||
vv, _ := consul.KVGet("hello", 0)
|
||||
fmt.Println(string(*vv))
|
||||
|
||||
for {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
|
|
|
|||
|
|
@ -135,27 +135,28 @@ func CheckHeath(serviceid string) {
|
|||
fmt.Println(b)
|
||||
}
|
||||
|
||||
//KVTest test
|
||||
func KVTest() {
|
||||
//KVPut test
|
||||
func KVPut(key string, values *[]byte, flags uint64) (*consulapi.WriteMeta, error) {
|
||||
client := getClient()
|
||||
if client == nil {
|
||||
return
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// KV, put值
|
||||
values := "test"
|
||||
key := "go-consul-test/127.0.0.1:8100"
|
||||
client.KV().Put(&consulapi.KVPair{Key: key, Flags: 0, Value: []byte(values)}, nil)
|
||||
return client.KV().Put(&consulapi.KVPair{Key: key, Flags: flags, Value: *values}, nil)
|
||||
}
|
||||
|
||||
//KVGet 获取值
|
||||
func KVGet(key string, flags uint64) (*[]byte, error) {
|
||||
client := getClient()
|
||||
if client == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// KV get值
|
||||
data, _, _ := client.KV().Get(key, nil)
|
||||
fmt.Println(string(data.Value))
|
||||
if data != nil {
|
||||
return &data.Value, nil
|
||||
}
|
||||
|
||||
// KV list
|
||||
datas, _, _ := client.KV().List("go", nil)
|
||||
for _, value := range datas {
|
||||
fmt.Println(value)
|
||||
}
|
||||
keys, _, _ := client.KV().Keys("go", "", nil)
|
||||
fmt.Println(keys)
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue