summaryrefslogtreecommitdiff
path: root/plugins/kv
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-05-05 16:39:22 +0300
committerValery Piashchynski <[email protected]>2021-05-05 16:39:22 +0300
commit4fa94bb7f73a705293c2afd40fc1151a3aaa04e2 (patch)
tree6ffd858cade87600bbd4432f70db22f50c598db0 /plugins/kv
parent9ee78f937d5be67058882dd3590f89da35bca239 (diff)
- Initial broadcast commit
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/kv')
-rw-r--r--plugins/kv/drivers/boltdb/driver.go3
-rw-r--r--plugins/kv/drivers/memcached/driver.go3
-rw-r--r--plugins/kv/drivers/memory/driver.go3
-rw-r--r--plugins/kv/rpc.go18
4 files changed, 14 insertions, 13 deletions
diff --git a/plugins/kv/drivers/boltdb/driver.go b/plugins/kv/drivers/boltdb/driver.go
index 2e2df527..0f647cb1 100644
--- a/plugins/kv/drivers/boltdb/driver.go
+++ b/plugins/kv/drivers/boltdb/driver.go
@@ -13,6 +13,7 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/kv"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/utils"
bolt "go.etcd.io/bbolt"
)
@@ -393,7 +394,7 @@ func (d *Driver) startGCLoop() { //nolint:gocognit
if b == nil {
return errors.E(op, errors.NoSuchBucket)
}
- err := b.Delete([]byte(k))
+ err := b.Delete(utils.AsBytes(k))
if err != nil {
return errors.E(op, err)
}
diff --git a/plugins/kv/drivers/memcached/driver.go b/plugins/kv/drivers/memcached/driver.go
index 17b06fa0..02281ed5 100644
--- a/plugins/kv/drivers/memcached/driver.go
+++ b/plugins/kv/drivers/memcached/driver.go
@@ -9,6 +9,7 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/kv"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/utils"
)
type Driver struct {
@@ -148,7 +149,7 @@ func (d *Driver) Set(items ...kv.Item) error {
memcachedItem := &memcache.Item{
Key: items[i].Key,
// unsafe convert
- Value: []byte(items[i].Value),
+ Value: utils.AsBytes(items[i].Value),
Flags: 0,
}
diff --git a/plugins/kv/drivers/memory/driver.go b/plugins/kv/drivers/memory/driver.go
index 1e0d03d4..c2494ee7 100644
--- a/plugins/kv/drivers/memory/driver.go
+++ b/plugins/kv/drivers/memory/driver.go
@@ -9,6 +9,7 @@ import (
"github.com/spiral/roadrunner/v2/plugins/config"
"github.com/spiral/roadrunner/v2/plugins/kv"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/utils"
)
type Driver struct {
@@ -70,7 +71,7 @@ func (s *Driver) Get(key string) ([]byte, error) {
if data, exist := s.heap.Load(key); exist {
// here might be a panic
// but data only could be a string, see Set function
- return []byte(data.(kv.Item).Value), nil
+ return utils.AsBytes(data.(kv.Item).Value), nil
}
return nil, nil
}
diff --git a/plugins/kv/rpc.go b/plugins/kv/rpc.go
index 240a28d1..2d4babbe 100644
--- a/plugins/kv/rpc.go
+++ b/plugins/kv/rpc.go
@@ -1,11 +1,10 @@
package kv
import (
- "unsafe"
-
"github.com/spiral/errors"
"github.com/spiral/roadrunner/v2/plugins/kv/payload/generated"
"github.com/spiral/roadrunner/v2/plugins/logger"
+ "github.com/spiral/roadrunner/v2/utils"
)
// Wrapper for the plugin
@@ -31,10 +30,10 @@ func (r *rpc) Has(in []byte, res *map[string]bool) error {
if !dataRoot.Items(tmpItem, i) {
continue
}
- keys = append(keys, strConvert(tmpItem.Key()))
+ keys = append(keys, utils.AsString(tmpItem.Key()))
}
- if st, ok := r.storages[strConvert(dataRoot.Storage())]; ok {
+ if st, ok := r.storages[utils.AsString(dataRoot.Storage())]; ok {
ret, err := st.Has(keys...)
if err != nil {
return err
@@ -73,7 +72,7 @@ func (r *rpc) Set(in []byte, ok *bool) error {
items = append(items, itc)
}
- if st, exists := r.storages[strConvert(dataRoot.Storage())]; exists {
+ if st, exists := r.storages[utils.AsString(dataRoot.Storage())]; exists {
err := st.Set(items...)
if err != nil {
return err
@@ -104,7 +103,7 @@ func (r *rpc) MGet(in []byte, res *map[string]interface{}) error {
keys = append(keys, string(tmpItem.Key()))
}
- if st, exists := r.storages[strConvert(dataRoot.Storage())]; exists {
+ if st, exists := r.storages[utils.AsString(dataRoot.Storage())]; exists {
ret, err := st.MGet(keys...)
if err != nil {
return err
@@ -143,7 +142,7 @@ func (r *rpc) MExpire(in []byte, ok *bool) error {
items = append(items, itc)
}
- if st, exists := r.storages[strConvert(dataRoot.Storage())]; exists {
+ if st, exists := r.storages[utils.AsString(dataRoot.Storage())]; exists {
err := st.MExpire(items...)
if err != nil {
return errors.E(op, err)
@@ -173,7 +172,7 @@ func (r *rpc) TTL(in []byte, res *map[string]interface{}) error {
keys = append(keys, string(tmpItem.Key()))
}
- if st, exists := r.storages[strConvert(dataRoot.Storage())]; exists {
+ if st, exists := r.storages[utils.AsString(dataRoot.Storage())]; exists {
ret, err := st.TTL(keys...)
if err != nil {
return err
@@ -201,7 +200,7 @@ func (r *rpc) Delete(in []byte, ok *bool) error {
}
keys = append(keys, string(tmpItem.Key()))
}
- if st, exists := r.storages[strConvert(dataRoot.Storage())]; exists {
+ if st, exists := r.storages[utils.AsString(dataRoot.Storage())]; exists {
err := st.Delete(keys...)
if err != nil {
return errors.E(op, err)
@@ -215,4 +214,3 @@ func (r *rpc) Delete(in []byte, ok *bool) error {
*ok = false
return errors.E(op, errors.Errorf("no such storage: %s", dataRoot.Storage()))
}
-