diff --git a/pkg/modules/keyvalue/memory/memory.go b/pkg/modules/keyvalue/memory/memory.go index 08a14547..6530f506 100644 --- a/pkg/modules/keyvalue/memory/memory.go +++ b/pkg/modules/keyvalue/memory/memory.go @@ -66,6 +66,11 @@ func (s *Storage) IncrBy(key string, update int64) (err error) { s.mutex.Lock() defer s.mutex.Unlock() + _, exists := s.store[key] + if !exists { + s.store[key] = int64(0) + } + val, is := s.store[key].(int64) if !is { return &e.ErrValueHasWrongType{Key: key, ExpectedValue: "int64"} @@ -80,6 +85,11 @@ func (s *Storage) DecrBy(key string, update int64) (err error) { s.mutex.Lock() defer s.mutex.Unlock() + _, exists := s.store[key] + if !exists { + s.store[key] = int64(0) + } + val, is := s.store[key].(int64) if !is { return &e.ErrValueHasWrongType{Key: key, ExpectedValue: "int64"}