1
0

Change keyvalue.Get to return if a value exists or not instead of an error

This commit is contained in:
kolaente
2021-01-31 12:32:46 +01:00
parent fe72f30b24
commit 2e88600c93
9 changed files with 28 additions and 43 deletions

View File

@ -20,9 +20,6 @@ import (
"context"
"encoding/json"
"github.com/go-errors/errors"
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
"code.vikunja.io/api/pkg/red"
"github.com/go-redis/redis/v8"
)
@ -52,13 +49,10 @@ func (s *Storage) Put(key string, value interface{}) (err error) {
}
// Get retrieves a saved value from redis
func (s *Storage) Get(key string) (value interface{}, err error) {
func (s *Storage) Get(key string) (value interface{}, exists bool, err error) {
b, err := s.client.Get(context.Background(), key).Bytes()
if err != nil {
if errors.Is(err, redis.Nil) {
return nil, &e.ErrValueNotFoundForKey{Key: key}
}
return nil, err
return nil, false, err
}
err = json.Unmarshal(b, value)