Refactor & fix storing struct-values in redis keyvalue
This commit is contained in:
parent
df45675df3
commit
d48aa101cf
10 changed files with 117 additions and 59 deletions
|
|
@ -17,6 +17,7 @@
|
|||
package memory
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sync"
|
||||
|
||||
e "code.vikunja.io/api/pkg/modules/keyvalue/error"
|
||||
|
|
@ -52,6 +53,21 @@ func (s *Storage) Get(key string) (value interface{}, exists bool, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *Storage) GetWithValue(key string, value interface{}) (exists bool, err error) {
|
||||
v, exists, err := s.Get(key)
|
||||
if !exists {
|
||||
return exists, err
|
||||
}
|
||||
|
||||
val := reflect.ValueOf(value)
|
||||
if val.Kind() != reflect.Ptr {
|
||||
panic("some: check must be a pointer")
|
||||
}
|
||||
|
||||
val.Elem().Set(reflect.ValueOf(v))
|
||||
return exists, err
|
||||
}
|
||||
|
||||
// Del removes a saved value from a memory storage
|
||||
func (s *Storage) Del(key string) (err error) {
|
||||
s.mutex.Lock()
|
||||
|
|
|
|||
Reference in a new issue