diff options
author | Valery Piashchynski <[email protected]> | 2021-06-08 22:36:40 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-08 22:36:40 +0300 |
commit | 4f3e16892479db4bd8280a46987f3105e46e5c96 (patch) | |
tree | 13c4c3f380d8309b95c9600cc2000d1d5ab87cda /plugins/kv/drivers/redis/driver.go | |
parent | 49ce25e80ba99ac91bce7ea2b9b632de53e07c0d (diff) | |
parent | cc271dceb13d3929f0382311dfce3dfed2ce04ce (diff) |
#712 feat(ws, kv): switch from the `flatbuffers` to the `protobuf`v2.3.0-beta.2
#712 feat(ws, kv): switch from the `flatbuffers` to the `protobuf`
Diffstat (limited to 'plugins/kv/drivers/redis/driver.go')
-rw-r--r-- | plugins/kv/drivers/redis/driver.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/plugins/kv/drivers/redis/driver.go b/plugins/kv/drivers/redis/driver.go index d0b541b2..0aaa6352 100644 --- a/plugins/kv/drivers/redis/driver.go +++ b/plugins/kv/drivers/redis/driver.go @@ -7,13 +7,12 @@ import ( "github.com/go-redis/redis/v8" "github.com/spiral/errors" + kvv1 "github.com/spiral/roadrunner/v2/pkg/proto/kv/v1beta" "github.com/spiral/roadrunner/v2/plugins/config" "github.com/spiral/roadrunner/v2/plugins/kv" "github.com/spiral/roadrunner/v2/plugins/logger" ) -var EmptyItem = kv.Item{} - type Driver struct { universalClient redis.UniversalClient log logger.Logger @@ -139,24 +138,24 @@ func (d *Driver) MGet(keys ...string) (map[string]interface{}, error) { // // Use expiration for `SETEX`-like behavior. // Zero expiration means the key has no expiration time. -func (d *Driver) Set(items ...kv.Item) error { +func (d *Driver) Set(items ...*kvv1.Item) error { const op = errors.Op("redis_driver_set") if items == nil { return errors.E(op, errors.NoKeys) } now := time.Now() for _, item := range items { - if item == EmptyItem { + if item == nil { return errors.E(op, errors.EmptyKey) } - if item.TTL == "" { + if item.Timeout == "" { err := d.universalClient.Set(context.Background(), item.Key, item.Value, 0).Err() if err != nil { return err } } else { - t, err := time.Parse(time.RFC3339, item.TTL) + t, err := time.Parse(time.RFC3339, item.Timeout) if err != nil { return err } @@ -188,15 +187,18 @@ func (d *Driver) Delete(keys ...string) error { // MExpire https://redis.io/commands/expire // timeout in RFC3339 -func (d *Driver) MExpire(items ...kv.Item) error { +func (d *Driver) MExpire(items ...*kvv1.Item) error { const op = errors.Op("redis_driver_mexpire") now := time.Now() for _, item := range items { - if item.TTL == "" || strings.TrimSpace(item.Key) == "" { + if item == nil { + continue + } + if item.Timeout == "" || strings.TrimSpace(item.Key) == "" { return errors.E(op, errors.Str("should set timeout and at least one key")) } - t, err := time.Parse(time.RFC3339, item.TTL) + t, err := time.Parse(time.RFC3339, item.Timeout) if err != nil { return err } |