A .gitignore => .gitignore +1 -0
@@ 0,0 1,1 @@
+.idea<
\ No newline at end of file
M README.md => README.md +2 -1
@@ 1,6 1,6 @@
# Kilovolt client
-Go client for Kilovolt websocket servers, supports Kilovolt Protocol v3/v4
+Go client for Kilovolt websocket servers, supports Kilovolt Protocol v3+
## Getting started
@@ 10,3 10,4 @@ Depending on what version of kilovolt you need to interface with, you'll need to
| -------- | ---------------------------------------------------- |
| `v3` | `go get github.com/strimertul/kilovolt-client-go` |
| `v4` | `go get github.com/strimertul/kilovolt-client-go/v2` |
+| `v5` | `go get github.com/strimertul/kilovolt-client-go/v3` |
M client.go => client.go +22 -1
@@ 14,7 14,7 @@ import (
cmap "github.com/orcaman/concurrent-map"
"github.com/sirupsen/logrus"
- kv "github.com/strimertul/kilovolt/v4"
+ kv "github.com/strimertul/kilovolt/v5"
)
var (
@@ 404,6 404,27 @@ func (s *Client) UnsubscribePrefix(prefix string, chn chan KeyValuePair) error {
return nil
}
+func (s *Client) ListKeys(prefix string) ([]string, error) {
+ resp, err := s.makeRequest(kv.Request{
+ CmdName: kv.CmdListKeys,
+ Data: map[string]interface{}{
+ "prefix": prefix,
+ },
+ })
+
+ if err != nil {
+ return nil, err
+ }
+
+ var keys []string
+ for _, k := range resp.Data.([]interface{}) {
+ if key, ok := k.(string); ok {
+ keys = append(keys, key)
+ }
+ }
+ return keys, nil
+}
+
func (s *Client) makeRequest(request kv.Request) (kv.Response, error) {
rid := ""
for {
M client_test.go => client_test.go +36 -1
@@ 9,7 9,7 @@ import (
"github.com/dgraph-io/badger/v3"
"github.com/sirupsen/logrus"
- kv "github.com/strimertul/kilovolt/v4"
+ kv "github.com/strimertul/kilovolt/v5"
)
func TestCommands(t *testing.T) {
@@ 232,6 232,41 @@ func TestPrefixSubscription(t *testing.T) {
}
}
+func TestKeyList(t *testing.T) {
+ log := logrus.New()
+ log.Level = logrus.TraceLevel
+
+ server, _ := createInMemoryKV(t, log)
+
+ client, err := NewClient(server.URL, ClientOptions{
+ Logger: log,
+ })
+ if err != nil {
+ t.Fatal("error creating kv client", err.Error())
+ }
+
+ if err = client.SetKey("test", "testvalue1234"); err != nil {
+ t.Fatal("error modifying key", err.Error())
+ }
+ if err = client.SetKey("multi1", "value1"); err != nil {
+ t.Fatal("error modifying key", err.Error())
+ }
+ if err = client.SetKey("multi2", "1234"); err != nil {
+ t.Fatal("error modifying key", err.Error())
+ }
+
+ list, err := client.ListKeys("multi")
+ if err != nil {
+ t.Fatal("error getting key list", err.Error())
+ }
+ if len(list) != 2 {
+ t.Fatal("wrong number of keys returned", len(list))
+ }
+ if list[0] != "multi1" || list[1] != "multi2" {
+ t.Fatal("wrong keys returned", list)
+ }
+}
+
func createInMemoryKV(t *testing.T, log logrus.FieldLogger) (*httptest.Server, *kv.Hub) {
// Open in-memory DB
options := badger.DefaultOptions("").WithInMemory(true).WithLogger(log)
M cmd/kvcli/main.go => cmd/kvcli/main.go +1 -1
@@ 7,7 7,7 @@ import (
"os"
"strings"
- kvclient "github.com/strimertul/kilovolt-client-go/v2"
+ kvclient "github.com/strimertul/kilovolt-client-go/v3"
)
func check(err error) {
M go.mod => go.mod +2 -2
@@ 1,4 1,4 @@
-module github.com/strimertul/kilovolt-client-go/v2
+module github.com/strimertul/kilovolt-client-go/v3
go 1.16
@@ 8,5 8,5 @@ require (
github.com/json-iterator/go v1.1.11
github.com/orcaman/concurrent-map v0.0.0-20210501183033-44dafcb38ecc
github.com/sirupsen/logrus v1.8.1
- github.com/strimertul/kilovolt/v4 v4.0.1
+ github.com/strimertul/kilovolt/v5 v5.0.1
)
M go.sum => go.sum +2 -4
@@ 90,12 90,10 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
-github.com/strimertul/kilovolt-client-go v1.1.1 h1:uy6y/WKJyubAPHb+wPJz5We+fVwzWIplHiclSAhEY2E=
-github.com/strimertul/kilovolt-client-go v1.1.1/go.mod h1:jXbd37kXDdDeKnOWao/JSNMdSYmuhBBHG+LWIBzuXr8=
-github.com/strimertul/kilovolt/v3 v3.0.0 h1:3gE0FdH3fL5UgMocR6Z7lI9hk3jD8ds8yL47D4Z7758=
-github.com/strimertul/kilovolt/v3 v3.0.0/go.mod h1:AgfPYRp+kffN64tcqCcQUZdpL/Dm5DGHIYRDm9t3E0Y=
github.com/strimertul/kilovolt/v4 v4.0.1 h1:81isohdSixVURO2+dZKKZBPw97HJmNN4/BXn6ADFoWM=
github.com/strimertul/kilovolt/v4 v4.0.1/go.mod h1:AO2ZFQtSB+AcjCw0RTkXjbM6XBAjhsXsrRq10BX95kw=
+github.com/strimertul/kilovolt/v5 v5.0.1 h1:LHAVqb3SrXiew3loTpYuPdz16Nl8/aTReBYj56xwF7I=
+github.com/strimertul/kilovolt/v5 v5.0.1/go.mod h1:HxfnnlEGhY6p+Im9U7pso07HEV+cXEsJH7uFTM7c6uE=
github.com/twitchyliquid64/golang-asm v0.15.0/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=