diff options
author | Valery Piashchynski <[email protected]> | 2021-02-06 01:39:15 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-02-06 01:39:15 +0300 |
commit | 7b63af9b205be85ed2a50408f762344e1aba1a46 (patch) | |
tree | 6a0d9c05f8e49abde402afac35fdb26b51d18f45 /plugins | |
parent | 11b357c4457dfcbc1ef79478c200b794b5486b13 (diff) |
Correct memcached Plugin RPC methods (remove redundant checks, user
errors.E)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/kv/memcached/plugin.go | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/plugins/kv/memcached/plugin.go b/plugins/kv/memcached/plugin.go index 181b8a49..b8392f9e 100644 --- a/plugins/kv/memcached/plugin.go +++ b/plugins/kv/memcached/plugin.go @@ -84,9 +84,13 @@ func (s *Plugin) Has(keys ...string) (map[string]bool, error) { return nil, errors.E(op, errors.EmptyKey) } exist, err := s.client.Get(keys[i]) - // ErrCacheMiss means that a Get failed because the item wasn't present. - if err != nil && err != memcache.ErrCacheMiss { - return nil, err + + if err != nil { + // ErrCacheMiss means that a Get failed because the item wasn't present. + if err == memcache.ErrCacheMiss { + continue + } + return nil, errors.E(op, err) } if exist != nil { m[keys[i]] = true @@ -105,9 +109,12 @@ func (s *Plugin) Get(key string) ([]byte, error) { return nil, errors.E(op, errors.EmptyKey) } data, err := s.client.Get(key) - // ErrCacheMiss means that a Get failed because the item wasn't present. - if err != nil && err != memcache.ErrCacheMiss { - return nil, err + if err != nil { + // ErrCacheMiss means that a Get failed because the item wasn't present. + if err == memcache.ErrCacheMiss { + return nil, nil + } + return nil, errors.E(op, err) } if data != nil { // return the value by the key @@ -137,9 +144,12 @@ func (s *Plugin) MGet(keys ...string) (map[string]interface{}, error) { for i := range keys { // Here also MultiGet data, err := s.client.Get(keys[i]) - // ErrCacheMiss means that a Get failed because the item wasn't present. - if err != nil && err != memcache.ErrCacheMiss { - return nil, err + if err != nil { + // ErrCacheMiss means that a Get failed because the item wasn't present. + if err == memcache.ErrCacheMiss { + continue + } + return nil, errors.E(op, err) } if data != nil { m[keys[i]] = data.Value @@ -205,7 +215,7 @@ func (s *Plugin) MExpire(items ...kv.Item) error { // verify provided TTL t, err := time.Parse(time.RFC3339, items[i].TTL) if err != nil { - return err + return errors.E(op, err) } // Touch updates the expiry for the given key. The seconds parameter is either @@ -215,7 +225,7 @@ func (s *Plugin) MExpire(items ...kv.Item) error { // The key must be at most 250 bytes in length. err = s.client.Touch(items[i].Key, int32(t.Unix())) if err != nil { - return err + return errors.E(op, err) } } return nil @@ -244,8 +254,12 @@ func (s *Plugin) Delete(keys ...string) error { for i := range keys { err := s.client.Delete(keys[i]) // ErrCacheMiss means that a Get failed because the item wasn't present. - if err != nil && err != memcache.ErrCacheMiss { - return err + if err != nil { + // ErrCacheMiss means that a Get failed because the item wasn't present. + if err == memcache.ErrCacheMiss { + continue + } + return errors.E(op, err) } } return nil |